I am new to java, I think this might be simple but I couldn't find the answer to my question anywere, maybe because I didn't phrase it right. I have this simple pseudo code, if I run it, it will seem as if nothing happens , I want the user to be able to see(icon2) for a few seconds, before it is changed back to icon.
I tried Thread.sleep but it didn't work, it worked on whatever else is inside (if) like a simple (print) but doesn't work on the interface. I think because it is in a the different thread, because I used Netbeans to create a frame class.
ImageIcon icon = new ImageIcon("somepath");
jLabel.setIcon(icon); //i give my label some icon
jLabel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
ImageIcon icon2 = new ImageIcon("some_otherpath");
jLabel1.setIcon(icon2); // The user clicks on the label so the icon changes
if(condition){ //if some condition is true i want the icon to change back
jLabel1.setIcon(icon); // if condition is not true, the label keeps icon2
// but i want the user to be able to see the change.
}
}
});
Thank you in advance.