Ok, so basically I want to use a swing timer and an actionListener and use thread.sleep in the middle of the actionPerformed method to make it wait 2 seconds before doing the next action. The problem is that when I add the code (and I use a try-catch to catch the interruptedException), it seems to ignore the wait and just go directly to the next action. Can anyone tell me the problem or suggest an alternative to using thread.sleep to wait a certain amount of time before going to the next action.
Here is the code for the actionPerformed method. The timer is firing every 3 seconds.
if(e.getSource() == t){ randButton = (int)(Math.random() * 16); holes.get(randButton).setIcon(moleOut); try { Thread.sleep(2000); } catch (InterruptedException ie) { holes.get(randButton).setIcon(moleIn); } }
Btw it's supposed to change the icon of a random button (out of the 16 buttons in the arrayList holes), wait 2 seconds, and then change it back.