My program starts by prompting the user to enter the number of masses they would like to orbit
public class textEvent1 implements ActionListener { //action listener for "how many masses?"
public void actionPerformed (ActionEvent e) {
n = (int)(Double.parseDouble(massNumField.getText()));
submit1.setVisible(false); //removes text event 1 text from screen
massNumLabel.setVisible(false);
massNumField.setVisible(false);
Then with that information I create that number of labels and text fields like so
for(int i=1; i<=n; i++) { //adds text event 2 text to the screen
massLabel = new JLabel("How much mass does Mass " +i+ " have? ");
massField = new JTextField(5);
xCorLabel = new JLabel("What is mass "+i+"'s starting x-coordinate?");
xCorField = new JTextField(5);
yCorLabel = new JLabel("what is mass "+i+"'s starting y-coordinate?");
yCorField = new JTextField(5);
xVelLabel = new JLabel("What is mass "+i+"'s starting x velocity?");
xVelField = new JTextField(5);
yVelLabel = new JLabel("What is mass "+i+"'s starting y velocity?");
yVelField = new JTextField(5);
add(massLabel);
add(massField);
add(xCorLabel);
add(xCorField);
add(yCorLabel);
add(yCorField);
add(xVelLabel);
add(xVelField);
add(yVelLabel);
add(yVelField);
}
Now my problem is reading from these text fields with with another actionlistner (a submit button) and assigning the value entered into an array. Since I dont know how many masses there will be I dont know how many text fields there will be and each text field essentially has the same name, how do I assign say the value entered for mass2's mass when its text field has the same name as all the other text fields?