最近我试图将一个普通终端的功能实现为一个图形化设计的基于Swing的控制台项目。我喜欢这里的一些人如何做到这一点,但我偶然发现了另一个大问题。有些人实际上谈到了InpuStreamListener
,虽然我不太喜欢这个。我工作的一个示例代码(几乎不完全矿,但它是我的应用程序的源代码)将是以下几点:获取并使用应用程序传递的InputStream
// Making an executor
org.apache.commons.exec.DefaultExecutor exec = new org.apache.commons.exec.DefaultExecutor();
// Creating the streams (pretty much ignore this, I just include it as a general idea of the method)
consoleOutputStream = new ConsoleOutputStream();
consoleInputStream = new JTextFieldInputStream(gsc.mainWindow.getConsoleInput().getJTextField());
// Stream Handler with the customized streams I use for the process
org.apache.commons.exec.PumpStreamHandler streamHandler = new org.apache.commons.exec.PumpStreamHandler(consoleOutputStream, consoleOutputStream, consoleInputStream);
// Setting the handler and finally making command line and executing
exec.setStreamHandler(streamHandler);
org.apache.commons.exec.CommandLine commandline = org.apache.commons.exec.CommandLine.parse(String.valueOf(arg));
exec.execute(commandline);
现在的事情是我通常尝试运行通过Java命令java应用程序通过这种方法。 OutputStream
工作得很好,没有任何缺陷,并给我所有它应该,但与输入应用程序给我很多麻烦。我beieve问题居住在硬编码System.in
,Scanner
类,Console
类等。所以这里是我需要一些帮助(最后): 我想要能够直接访问传递给我的应用程序或某人InputStream
向我解释了如何实际编写一个InputStreamListener
,当我运行外部java应用程序(是的,我通过我的界面而不是cmd或终端运行它们,我试图在这里创建一个工具)时,它会偶尔使用。如果这太复杂了,需要在我身边进行很多调整,或者通常是不可能的,有人可以帮助我获得传递的InputStream
,所以我实际上可以编写一个类来允许我编写特定于我的界面的应用程序?
在此先感谢,甚至非常感谢您花时间阅读全文! :)
不管谁知道为什么'event-dispatch-thread'标签被@mKorbel编辑,他们能解释它吗?谢谢! :) –
所有事件到AWT,Swing GUI必须在事件派发上完成Tread – mKorbel