1

in my Keyboardclass i have 3 difrent jTextareas (jTextareas1, jTextareas2, jTextareas3). Normaly i call them with keyboardwindow.jTextArea1.setText(); or keyboardwindow.jTextArea1.setBackground(); in my main.

But is there a way to use them in a loop in my main something like:

 for(int n=1; n<=4; n++){ 
       keyboardwindow.jTextAreai.setText();
 }
QFireball
  • 39
  • 3
  • Yes, put them in an array or a `List` (or any kind of collection you want), then iterate over them. – byxor Jun 26 '17 at 11:01

1 Answers1

-1

You can use an array or List to store the JTextArea objects.

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

for(JTextArea textAreaObj: textAreas){
     keyboardwindow.textAreaObj.setText();
}
Jude Niroshan
  • 4,280
  • 8
  • 40
  • 62
  • `keyboardwindow.textAreaObj` shouldn't work as far as I'm aware. Since you already have the references, it's unnecessary anyway. – byxor Jun 26 '17 at 12:40