2017-06-26 14 views
1

在我的Keyboardclass中,我有3個不同的jTextareas(jTextareas1,jTextareas2,jTextareas3)。通常我使用keyboardwindow.jTextArea1.setText()來調用它們。 或keyboardwindow.jTextArea1.setBackground();在我的主要。如何在循環中調用不同的jTextareas?

但有使用它們在一個循環中我主要是這樣一種方式:

for(int n=1; n<=4; n++){ 
     keyboardwindow.jTextAreai.setText(); 
} 
+0

是的,把它們放在一個數組或List中(或任何你想要的集合),然後遍歷它們。 – byxor

回答

-1

您可以使用數組或List存儲的JTextArea對象。

JTextArea[] textAreas = new JTextArea[]; 
//initialize and assign the TextAreas inside a initialization method 

for(JTextArea textAreaObj: textAreas){ 
    keyboardwindow.textAreaObj.setText(); 
} 
+0

'keyboardwindow.textAreaObj'應該不會像我所知道的那樣工作。既然你已經有了參考資料,反正沒有必要。 – byxor

相關問題