简体   繁体   中英

How do I successfully use the Thread.sleep() method in Graphics?

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 (ie 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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM