My JButtons aren't being changed in this action listener:
dice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int array [] = new int [5];
for(int i = 0; i < 5; i++)
{
array [i]= (int) (Math.random () * 6) + 1;
System.out.println(array[i]);
}
final JButton roll1 = new JButton(diceIcons[array[0]-1]);
final JButton roll2 = new JButton(diceIcons[array[1]-1]);
final JButton roll3 = new JButton(diceIcons[array[2]-1]);
final JButton roll4 = new JButton(diceIcons[array[3]-1]);
final JButton roll5 = new JButton(diceIcons[array[4]-1]);
roll1.setBounds(40, 100, 70, 70);
roll2.setBounds(40, 180, 70, 70);
roll3.setBounds(40, 260, 70, 70);
roll4.setBounds(40, 340, 70, 70);
roll5.setBounds(40, 420, 70, 70);
//Adding to JFrame
panel.add(roll1);
panel.add(roll2);
panel.add(roll3);
panel.add(roll4);
panel.add(roll5);
panel.doLayout();
panel.repaint();
panel.revalidate();
}
});
I have the array that generates random numbers and as a test I put a system.out.println(array[i]) and when i click the button the numbers are generated and the images corresponding the numbers are generated but after the first time if i were to click it again the array does change because a new 5 numbers appears in the system.out.println but the JButtons do not change.
Aucun commentaire:
Enregistrer un commentaire