简体   繁体   English

如何在其他Java应用程序(而非GUI)的Java GUI中显示输出?

[英]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? 请帮助我了解如何获取常规Java工具的输出并将其显示在Java Swing应用程序的textArea组件中? The regular java application(not gui) can already get a file via cmd and does make an output in console. 常规的Java应用程序(非gui)已经可以通过cmd获取文件,并且可以在控制台中进行输出。 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) . 现在,我的场景是当我在Java Gui中加载文件时,里面的所有数据都将发送到此Java应用程序(jar文件不是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. 以及如何获取输出流以便在Java Gui应用程序的textArea中显示它。 The code below is in Java Gui application. 下面的代码在Java Gui应用程序中。

    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. 在gui应用程序的textArea中,我什么都看不到,直到它在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);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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