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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.