This is my code so far:
// Imported Classes
public class Timer extends Applet
{
public void paint (Graphics page) throws InterruptedException
{
Thread.sleep(1000);
}
}
I just want to know how I can get this to work. I've used the Thread.sleep() method in other code before, but never with Graphics. I don't have much experience with Exceptions either, I usually try my best to avoid or correct them.
You should never call methods such as Thread.sleep
on the event dispatch thread (i.e. in paint methods). This will render the whole GUI unresponsive.
You should instead use timers such as SwingTimer
to perform animations etc. See the following related questions: