2-Dimensional Array and input
Okay. I'm taking an Intro to Programming I class. One of the assignments for completion involves building an app (as you'd expect). I have a fair understanding of the overall goal and how to get there, but I keep tripping up on the input-and-array portion. ArrayList seems like it would work better for this purpose but the instructions explicitly state to create and use a 2-dimensional array. I can figure out how to initialize a 2-D array, but it's the input part that I get hung up on. I've done the basic "take input, print input" but I'm totally blanking on how to get a GUI button to take input from 2 text fields (integers) and store them in this array. After that I have to perform a number of functions against this information (totals and averaging) but that part I think I can handle.
What's the process for taking input from 2 fields (via a button click) and storing into an array?
Re: 2-Dimensional Array and input
Assuming that you are referring to a JTextField, there is a method called getText() that will return a String whose value is the contents of that JTextField.
Approach it step by step:
1)Retrieve the value from the JTextField, and store it in a variable
String userInput = myJTextField.getText();
2)Repeat the process for your 2nd JTextField, and store it's value in another variable.
3) Storing those 2 values in a 2D Array is simply a matter of knowing which array you want to store the value in, and at what index in that array you want to store it in. Just be sure that you have initialized the Array beforehand.