I'm trying to display an image (iconLabel4) for 5 seconds and then display another image (imageLabel) on top of it after. Why doesn't the code work as intended?
When I run it, what happens is this: I press the button "Bathe" and nothing happens.
I would appreciate any help! Thank you.
Code:
JButton bathe = new JButton("Bathe");
bathe.setBounds(370, 450, 80, 25);
bathe.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event){
long startTime=System.currentTimeMillis();
String actionCommand = event.getActionCommand();
if (SHOW_ACTION.equals(actionCommand)){
while (System.currentTimeMillis() - startTime < 5000) {
iconLabel4.setVisible(true);
} }
iconLabel4.setVisible(false);
imageLabel.setVisible(true);
repaint();
};
});
bathe.setActionCommand(SHOW_ACTION);
panel.add(bathe);