My trouble is coming from trying to record which array is being chosen. As in, if I have an array of 5 elements, recording that the 3rd element is being chosen. To put into context, I have 2 different arrays each with 10 elements; one array is made up of integers (called money), and the other is an array of JButtons.
public class Game extends JFrame {
JPanel cases = new JPanel(new GridLayout(2, 5)); //Section containing game cases
JButton[] caseButton = new JButton[10]; // Declaration of the
String gameCase[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; // case buttons
int[] money = {1, 2, 5, 10, 100, 1000, 5000, 10000, 20000, 30000}; //money values
}
public void StartGame() {
Shuffle(money); //Shuffle the money
//Initialising case buttons
for (int i = 0; i < caseButton.length; i++) {
caseButton[i] = new JButton(gameCase[i]);
cases.add(caseButton[i]);
caseButton[i].setPreferredSize(new Dimension(100, 100));
caseButton[i].setFont(new Font("Dialog", Font.BOLD, 35));
caseButton[i].setForeground(new Color(255, 215, 0));
caseButton[i].setActionCommand(gameCase[i]);
}
The Money array is being shuffled at the start of the program to allow for a different order on each run. What I want to know is when one of these JButtons is selected, how can I record which Array element was selected? So I can then do stuff with the corresponding money array. (Eg, the 7th JButton is chosen, I want to then change the text of the JButton to the number held in the 7th money array.) Help would be greatly appreciated. This is due next week and there's still so much more that needs to be done.