在Java中使用GUI进行控制台输入和输出 [英] Using GUI for console input and outputin java

查看:977
本文介绍了在Java中使用GUI进行控制台输入和输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将控制台信息输出到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()方法来编写通常在控制台上编写的内容。示例:

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

详情请参阅API

这篇关于在Java中使用GUI进行控制台输入和输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆