Easiest way to show text in gui?

时间:2016-04-04 17:01:22

标签: java

I've seen many posts about it, but it looks complicated. Here is my code, what would be the easiest way to display information on gui textArea?

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++;
   }
 }

1 个答案:

答案 0 :(得分:0)

Easiest way would be

textAreaName.setText(/*What ever you want to display here*/);

In your case it would be the following if you wanted to just set the text to s:

textArea.setText(s + "\n");

If you wanted to update the text along with the existing text you would use:

textArea.append(s + "\n");