Hi All,
I am a newbie at java and need some help. I have a JFrame setup where basically I want to show two pictures. I have everything setup however at sleep, timers ect dont currently work and I dont know why. The snipplet of code below should show imagePanel1 first then after 5seconds remove imagePanel1 then add imagePanel2 to the frame. However when I start it the first 5seconds shows nothing but a transparent frame then it shows imagePanel2 after 5seconds. Anyone know why this might be happening and how to fix it. I've already tried to use Thread.sleep(5000); but still no luck and same is happening.
static class previewAction implements ActionListener {
final int seconds = 5;
final long start = System.currentTimeMillis();
public void actionPerformed(ActionEvent e) {
previewFrame.setVisible(true);
imageLabel1.setIcon(imageIcon1);
imagePanel1.add(imageLabel1);
imageLabel2.setIcon(imageIcon2);
imagePanel2.add(imageLabel2);
previewFrame.getContentPane().add(imagePanel1);
long a1 = System.currentTimeMillis();
while(true) {
long b1 = System.currentTimeMillis();
if(b1-a1 >= 5000) break; // Elapsed 5s
previewFrame.getContentPane().remove(imagePanel1);
previewFrame.getContentPane().add(imagePanel2);
}
}
}