简体   繁体   中英

How to display the output in java gui of other java application(not gui)?

please help me to understand how to get an output of regular java tool and display it in textArea component of Java Swing Application? The regular java application(not gui) can already get a file via cmd and does make an output in console. Now, my scenario is when i'm loading the file in Java Gui , then all data inside will be sent to this java application(jar file not gui) . I do like this but further i'm stack. Where to send input? and how to get the output stream in order to display it in textArea of Java Gui application. The code below is in Java Gui application.

    String cmd =MessageFormat.format("java -jar tooling-gott-extended.jar -defaultMID {0} -urls {1} -src {2} -exclude {3}", 
                    comboBoxMid.getSelectedItem(),
                    comboBoxGate.getSelectedItem(),
                    selectedFileTC.toString(),
                    " ");


            ProcessBuilder   pb = new ProcessBuilder(cmd);
            pb.redirectErrorStream(true);
            Process  p = pb.start();

BufferedReader input = new BufferedReader(new 
                                        InputStreamReader(p.getInputStream()));

i found how to do that , here is the code how to execute it if somebody need it. But i have now other challenge. I don't see nothing in textArea of gui application until it completes to execute behind in cmd. How to display parallel?

String path = "C:\\Eclipse\\workspace_automation\\gui-tool\\java.jar";
    String cmd = MessageFormat.format("java -jar {0}  param1 {1} param2 {2} param3 {3}", path,
            comboBoxMid.getSelectedItem(), comboBoxGate.getSelectedItem(), selectedFileTC.toString());

    ProcessBuilder pb = new ProcessBuilder("cmd", "/c", cmd);
    pb.redirectErrorStream(true);
    Process p = pb.start();
    BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));

    String line;
    while (true) {
        line = r.readLine();
        if (line == null) {
            break;
        }
        System.out.println(line);
        textArea.append("\n"+line);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM