【发布时间】:2014-04-16 08:41:03
【问题描述】:
基本上,这段代码是从一个 JButton(在另一个类中)调用的,通过一遍又一遍地重新绘制来移动立方体。我希望创建另一个 JButton 以从另一种方法停止计时器 (timer.stop())。我该怎么做呢
private ActionListener actionListener ;
public void moveCube()
{
actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
cube.moveBox(7,5);
repaint();
}
};
Timer timer = new Timer( 100, actionListener );
timer.start();
}
【问题讨论】:
标签: java timer jbutton actionlistener actionevent