Timer in java using Eclipse

前端 未结 3 944
小蘑菇
小蘑菇 2021-01-21 15:37

I\'m trying to do a little program in Java using Eclipse, and I\'m a little bit lost.

Could anybody explain me (in a \"for dummies way\") what do I have to do for repain

3条回答
  •  不要未来只要你来
    2021-01-21 16:00

    you have to split that to the separete methods, better would be using javax.swing.Action instead of ActionListener

    private void activateTimer(){
        myTimer = new Timer(1000, myAction);
        myTimer.start();
    }
    
    private Action myAction = new AbstractAction() {
    
        private static final long serialVersionUID = 1L;
    
        @Override
        public void actionPerformed(ActionEvent e) {
              whatever.redraw();
        }
    };
    

提交回复
热议问题