최근에 그래픽으로 디자인 된 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);
이제 일이 내가 일반적으로 자바 명령을 통해 자바 응용 프로그램을 실행하려고한다 이 방법을 통해. OutputStream
은 정말 잘 작동하고 결함이 전혀 없어 내게 모든 것을 제공하지만 입력이있는 응용 프로그램은 많은 문제를 일으 킵니다. 나는 문제가 System.in
, Scanner
클래스, Console
클래스 등의 하드 코딩에 상주합니다. 그래서 여기에 내가 어떤 도움이 필요합니까 (마침내) : InputStream
내 응용 프로그램이나 누군가에게 전달할 수 있습니다. 내가 실제로 외부 Java 응용 프로그램을 실행할 때 사용되는 InputStreamListener
을 작성하는 방법을 설명합니다 (예, cmd 또는 터미널 대신 내 인터페이스를 통해 실행합니다. 여기에 도구를 만들려고합니다). 이 작업이 너무 복잡하고 내 편이 많이 필요하거나 일반적으로 불가능한 경우 누군가가 전달 된 InputStream
을 얻도록 나를 도울 수 있으므로 실제로 인터페이스에 특정한 응용 프로그램을 작성할 수있는 클래스를 작성할 수 있습니까?
미리 감사 드리며이 전체 텍스트를 읽을 시간을 가졌습니다. :)
'event-dispatch-thread' 태그가 @mKorbel에 의해 편집 된 이유를 알고있는 사람이라면 누구나 설명 할 수 있습니까? 감사! :) –
AWT에 대한 모든 이벤트, Swing GUI는 Event dispatch Tread에서 수행해야합니다. – mKorbel