【发布时间】:2013-03-14 17:29:22
【问题描述】:
我有一个实现Actionlistener 的类。单击此类中的按钮后,我希望它在我指定的精确时间,更早和其他地方执行某些操作。所以我做了这些课程:
class DoSomething implements ActionListener{
public void actionPerformed(ActionEvent a){
while(true){
String test = obtainTime.time;
if(test.matches("(.*)17:29:30(.*)")){
Class.doSomethingMethod();
}
//Rest of the code
}
}
}
class ObtainTime{
static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
static Calendar cal = Calendar.getInstance();
static String time = dateFormat.format(cal.getTime());
}
所以问题是,我只得到点击它的时间。第二件事是按钮变得不可点击,因为它仍在运行,有没有办法让它在代码仍在后台运行时再次可点击?感谢您的帮助。
【问题讨论】:
-
你需要使用线程。
-
你永远不会设置那些静态字段
标签: java swing time system actionlistener