【发布时间】:2013-08-01 02:48:08
【问题描述】:
我有一个简单的 2d 游戏类,如下所示:
public class Game extends JPanel implements ActionListener {
private Timer timr;
public Game(){
//other stuff
timr = new Timer(10, this);
timr.start();
}
//other methods including ActionListener-related ones
}
而不是使用 Timer() 作为我想将 Game 作为线程运行的时间,我怎样才能做到这一点并保留 ActionListener 函数?
【问题讨论】:
-
可以实现多个接口,实现Runnable。实现 ActionLister、Runnable{}
-
这取决于,
ActionListener实际上是做什么的?您可能需要阅读 Concurrency in Swing 以了解 Swing 和 Threads 的一些问题 -
@MadProgrammer
ActionListener获取击键并在屏幕上移动精灵。 -
@arynaq 谢谢,这回答了我的问题。
标签: java swing timer actionlistener multiple-inheritance