Java 在gui中显示文本的最简单方法?
我看过很多关于它的帖子,但看起来很复杂。这是我的代码,在gui textArea上显示信息最简单的方法是什么Java 在gui中显示文本的最简单方法?,java,Java,我看过很多关于它的帖子,但看起来很复杂。这是我的代码,在gui textArea上显示信息最简单的方法是什么 public static void runSystemCommand(String command) { String message=null; int i=0; while (i<1) { try { Process p = Runtime.getRuntime().exec(command); Buffered
public static void runSystemCommand(String command) {
String message=null;
int i=0;
while (i<1) {
try {
Process p = Runtime.getRuntime().exec(command);
BufferedReader inputStream = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String s = "";
// reading output stream of the command
while ((s = inputStream.readLine()) != null) {
//here i dont know what to type..please help
}
Thread.sleep(9000);
} catch (Exception e) {
e.printStackTrace();
}
i++;
}
}
publicstaticvoid运行系统命令(String命令){
字符串消息=null;
int i=0;
而(i最简单的方法是
textAreaName.setText(/*What ever you want to display here*/);
在您的情况下,如果您只想将文本设置为s
,则如下所示:
textArea.setText(s + "\n");
如果要随现有文本一起更新文本,请使用:
textArea.append(s + "\n");
最简单的方法是
textAreaName.setText(/*What ever you want to display here*/);
在您的情况下,如果您只想将文本设置为s
,则如下所示:
textArea.setText(s + "\n");
如果要随现有文本一起更新文本,请使用:
textArea.append(s + "\n");
这是关于JTextArea的,还是您只是想要类似于JavaScript的alert()
?textArea.append(s+“\r\n”)
应该适用于这种情况?假设您已经有了对的引用,您需要类似于txtArea.append(s+System.getProperty(“line.separator”))的内容
;程序从CMD控制台读取,它是一个ping主机程序。这是关于JTextArea的,还是您只是想要类似于JavaScript的alert()
?textArea.append(s+“\r\n”)
应该适用于这种情况?假设您已经有了对的引用,您需要类似于txtArea.append的东西(s+System.getProperty(“line.separator”)
;程序从CMD控制台读取,CMD控制台是一个ping主机程序。