在 netbeans 中将控制台应用程序与 GUI 结合起来
我想将控制台应用程序与 netbeans 中的 GUI 结合起来。我尝试使用 jButton 来实现。我想将控制台应用程序的输出放入 jTextArea 中。
控制台应用程序中有一个名为 private static void printBytes(byte[] data, String name)
的函数。调用该函数时必须执行以下操作。
printBytes(activeKey,"After permuted choice 1 table- Active key:");
为此,我必须将第二个参数传递给文本框。我创建了一个名为 ta
的 jTextArea
对象,并给出了
printBytes(activeKey,ta.append("After permuted choice 1 table- Active key:"));
一个名为
无法将 void 类型转换为字符串。
然后我尝试如下。
String a="After permuted choice 1 table- Active key:"
printBytes(activeKey,ta.getText(a));
它也不起作用。 有人请告诉我该怎么做。我想做的是以某种方式将我的控制台应用程序连接到 GUI 并在 GUI 上获取输出。
I want to combine a console application with a GUI in netbeans.I tried to do it using a jButton. I want to get the output of the console application into a jTextArea.
There is a function called private static void printBytes(byte[] data, String name)
in the console application. When calling that function have to do as follow.
printBytes(activeKey,"After permuted choice 1 table- Active key:");
For this I have to pass the 2nd parameter to the text box. I created an object of the jTextArea
called ta
and gave
printBytes(activeKey,ta.append("After permuted choice 1 table- Active key:"));
It gave an error called
Cannot convert void type into string.
Then I tried as follow.
String a="After permuted choice 1 table- Active key:"
printBytes(activeKey,ta.getText(a));
It also didn't work.
Someone please tell me how to do it.What i want to do is somehow connect my console application to GUI and getting the output on the GUI.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cannot conversion void type into string.
告诉您到底出了什么问题。您调用的方法 JTextArea#append(...) 不返回字符串,而是将文本附加到其显示中,并且不返回任何内容,void,因此您无法将方法的结果(没有)传递到您的 printBytes 方法需要一个字符串。您可以通过将标准输出重定向到 JTextArea 将控制台应用程序“连接”到 GUI,但您最好创建一个 GUI 应用程序,而不是尝试将控制台连接到 GUI开始使用非 GUI 模型,该模型保存其逻辑并编写为可以在您选择的大多数 UI、控制台、GUI 或其他(如果存在)中使用。
Cannot convert void type into string.
tells you exactly what is wrong. The method you're calling, JTextArea#append(...) doesn't return a String but rather appends text to its display, and returns nothing, void, so you can't pass the method's result (there is none) into your printBytes method which expects a String.You can "connect" a console app to a GUI by re-directing the standard output into the JTextArea, but again rather than trying to connect a console to a GUI, you're likely better to create a GUI app that is GUI from the get-go with a non-GUI model that holds its logic and is written so that it can be used in most any UI you choose, console, GUI or other (if it exists).