I have a Java Program that I need to create that will show five random images selected form my image folder of 50 images. upon clicking a button the program should select 5 new random images. I have most of it figured out except for my ActionListener. Is it possible to implement an ActionListener that will simply run my main class over again thereby "restarting" the program and selecting 5 new images?
//Creat JButton
JButton jbtNew = new JButton("New Cards");
//Initialize Variables
int number1 = (int)(Math.random()*54+1);
int number2 = (int)(Math.random()*54+1);
int number3 = (int)(Math.random()*54+1);
int number4 = (int)(Math.random()*54+1);
int number5 = (int)(Math.random()*54+1);
private ImageIcon card1 = new ImageIcon(number1 + ".png");
private ImageIcon card2 = new ImageIcon(number2 + ".png");
private ImageIcon card3 = new ImageIcon(number3 + ".png");
private ImageIcon card4 = new ImageIcon(number4 + ".png");
private ImageIcon card5 = new ImageIcon(number5 + ".png");
use varibles for labels
first declare in proper place: JLabel label1;
In constructor create new instance of label: label1 = new JLabel(card1);
add this label ...
///
In method actionPerformed your labels stays avilable to set new icons
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.