Using GUI for console input and outputin java

孤街醉人 提交于 2020-01-04 09:54:34

问题


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?


回答1:


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.");

See the API for details




回答2:


I know this was 2 years ago but, for any anyone else trying to accomplish the same thing, there is Java file that can add the functionality to input and output information to a GUI console and it can be found here.



来源:https://stackoverflow.com/questions/10128309/using-gui-for-console-input-and-outputin-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!