在Java中使用GUI进行控制台输入和输出 [英] Using GUI for console input and outputin java
问题描述
我如何将控制台信息输出到GUI?我有一个具有GUI的应用程序,直到用户在类似于Linux中的CLI的目录中移动。因此,我如何将来自控制台的输出和输入移植到GUI中。使用JPanel还是可以呢?
How would I output console information to a GUI? I have a application that has a GUI up till I have the user move within directories similar to the CLI in linux. So how would I port the output and input from a console into a GUI. Would JPanel be the way to go or something else?
推荐答案
技术上,如果您愿意,可以使用 JTextArea
来完成这个。您可以使用JTextArea的 append()$ c来代替向控制台写入通常要写的内容,例如告诉程序员某些事情成功或不成功的信息(当然是用于故障排除)。 $ c>方法来编写通常在控制台上编写的内容。示例:
Technically, if you wanted to, you could use JTextArea
to accomplish this. Instead of writing to the console what you'd normally write, such as some information telling the programmer that something was successful or unsuccessful (for troubleshooting of course), you can use JTextArea's append()
method to write what you would normally write on the console. Example:
javax.swing.JTextArea guiConsole = new JTextArea(10,10); //Just so you know what this is
System.out.println("This sentence is printed to the real console.");
guiConsole.append("But this one is printed to the GUI Console we made.");
这篇关于在Java中使用GUI进行控制台输入和输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!