how does a swing timer work?

后端 未结 3 1071
一生所求
一生所求 2021-01-17 06:34

hello i am having trouble trying to understand swing timers. to help me could someone show me a simple flickering animation? i have looked arround on the internet but still

3条回答
  •  既然无缘
    2021-01-17 07:17

    maybe this would help:

    public class object{
    Color color = Color.GREEN;
    Timer timer;
    public object() {
    
    timer = null;
    timer = new Timer(5000, new ActionListener(){
        public void actionPerformed(ActionEvent e) {
            if (color.equals(Color.GREEN)) {
                color = Color.RED;
                timer.setDelay(2000);
            } else {
                color = Color.GREEN;
                timer.setDelay(8000);
            }
            repaint();
        }
    });
    timer.start();}}
    

提交回复
热议问题