
- 类名以大写字母开头,即
Help
- Swing组件应在以下位置创建和修改
Event Dispatch Thread
- 这样
Thread
创建一个新的:Thread t = new Thread(new Runnable() {@Overridepublic void run() { //work here}});
t.start();//start thread
但是我建议在
Timer它上运行一个Swing
EDT:
- 如何使用摇摆计时器
编辑:
根据您的问题,我建议使用
Timer创建线程点用于一般知识。
探测是线程未在您的swing GUI的EDT线程上运行,就像
Timer这样:
int delay = 1000; //milliseconds ActionListener taskPerformer = new ActionListener() { int count=0; public void actionPerformed(ActionEvent evt) {if(count==10) {//we did the task 10 times ((Timer)evt.getSource()).stop(); } label.setLocation((label.getLocationOnScreen().x+10), label.getLocationOnScreen().y); System.out.println(SwingUtilities.isEventDispatchThread());count++; } }; new Timer(delay, taskPerformer).start();参考:
- http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)