0

Hey Fellas,

I created 10 JTextFields using and ArrayLists:

ArrayList<JTextField> textFArray = new ArrayList<>();

textFArray.add(new JTextField());
gbc.gridx = 1;
for (int i = 0; i < 10; i++) {
   gbc.gridy++;
   add(textFArray.get(i), gbc);
   textFArray.add(new JTextField(i));
}

What I need to do:
I need to get the values of what ever the user puts into the JTextField(s) and total the inputs and assign them to a variable. This is what I have so far:

double totalTemp;
for(JTextField temps: textFArray){
    //System.out.println(temps.getText());
    totalTemp = Integer.parseInt(temps.getText());
}

I know the code snippet above doesnt work properly. If you uncomment the the one line, it can display the inputs. But the problem is adding them.
Would it be possible to put them into an ArrayList? This would be great as it would give me the ability to perform comparisons as well.

2
Contributors
1
Reply
18
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

Why not just create an empty ArrayList<Integer> before entering that loop, then inside the loop just add each parsed int value to that ArrayList? Then you will have an arraylist with all the values, where you can do whatever processing or calculations you want.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.