更改文本我想無論何時運行下面的print()方法來改變JTextArea中的文本。整個程序很長,所以我只能發佈一點點,但基本上[50] [50]字符數組包含正在變成50行50個字符的字符串。包含這個JTextArea的JFrame是在按下按鈕時啓動的,並立即將char數組輸出到JTextArea中(當我創建它時,char數組永遠不會更新)。該計劃旨在每隔幾秒更新一次該文本。在JTextArea中
但是,不是每秒更新一次,直到上次運行PRINT()時,JFrame基本上都顯示爲空白框。目前,它打算通過對PRINT()的10次調用以單獨的行打印1 ... 10,每次在output.outputLines已更新後添加數字。相反,它只顯示一個空白幀,直到最後一個數字被加載,然後打印整個事情。
print()方法:
public boolean PRINT(){
String result = ""; //Used to hold the characters to be printed to the screen
for(int x = 0; x<50; x++){
for(int y = 0; y<50; y++) {
result = result + String.valueOf(output.outputLines[x][y]);
}//End of inner FOR statement
result = result + "\n";
output.jTextArea1.setText(result);
}//End of outer FOR statement
return true;
}
代碼中使用PRINT之間暫停()調用:
try {
java.lang.Thread.sleep(1000);
catch (Exception ex) {
System.out.println("Exception in Thread.sleep()");
任何人可以幫助我弄清楚是怎麼回事了?
我可以看到這個是問題的一個確切的重複? – user2465510