2014-03-26 91 views
0

我使用Swing設計了一個使用Java的GUI。將python輸出日誌動態重定向到Java GUI

使用GUI我讀的位置爲輸入

使用這些輸入作爲參數,我叫Python的腳本從這個Java代碼

現在,我需要動態顯示python腳本對GUI的輸出。 當python腳本運行時,腳本的輸出日誌必須同時顯示在GUI區域上。

無論如何我能做到嗎?

請幫

+0

一些代碼將看到你目前做何新的代碼可以放在/ – Stewartside

+0

您可以使用介紹的方法[有用這裏](http://stackoverflow.com/a/15111352/230513)。 – trashgod

回答

0

A碼將是有益的,但是,你可以寫在文件上python腳本輸出比從文件中讀取到Java GUI時輸出。

的Python

out_file = open("test.txt","w") 
out_file.write("This Text is going to out file\nLook at it and see\n") 
out_file.close() 

JAVA

File name = new File("C:/path/test.txt"); 

if (name.isFile()) { 

    try { 

     BufferedReader input = new BufferedReader(new FileReader(name)); 
     StringBuffer buffer = new StringBuffer(); 

     String text; 

     while ((text = input.readLine()) != null){ 

      buffer.append(text + "\n");} 

     input.close(); 
     System.out.println(buffer.toString()); 

    } catch (IOException ioException) {} 

} 
相關問題