Vector for JTextField [closed]

-1

I have to add 43 fields of text that the user will fill out the ones that will be used to have a total and that total will be used in my formula and I could not find a solution to reduce those lines that I did manually by assigning a variable each field. My question is:

Can I create a Vector to receive text fields like this? how would the formula to get a Jtext and get the next value and go adding?

    
asked by anonymous 26.09.2017 / 16:34

1 answer

1

You can loop all the components in your dashboard and if it is an instance of JTextField , you add. Ex:

Double total = 0.00;    

for (Component c : painel.getComponents()) {    
    if (c instanceof JTextField) {
        total += Double.parseDouble(((JTextField) c).getText());
    }
}

But remember that all of your% of% used in the calculation should be in the same panel.

    
26.09.2017 / 16:48