我想问一下,当第一次移动鼠标时,如何在定时器启动时进行60秒倒计时(并在标题中显示)。然后在最后我想显示一些jOptionPane.Message或其他东西。这是代码......
private void jPanel2MouseMoved(java.awt.event.MouseEvent evt) {
jPanel1.setBounds(evt.getX(), evt.getY(), jPanel1.getWidth(), jPanel1.getHeight());
int a = KEK.nextInt(jPanel2.getWidth()-15);
int b = KEK.nextInt(jPanel2.getHeight()-15);
if(jPanel1.getBounds().intersects(jPanel3.getBounds()) == true){
rurin++;
jPanel3.setBounds(a, b, jPanel3.getWidth(), jPanel3.getHeight());
this.setTitle("Number of red dots touched: " +rurin+" ");
}
}
答案 0 :(得分:0)
ActionListener
的类的实例:示例EmilsListener list = new EmilsListener();
Timer
类的实例,并传递对象及其重新启动的时间:Timer tym = new Timer(1000,list);
接受的答案中查看完整的计时器示例tym.addActionListener(list); tym.start();//But before this make sure you defined the EmilsListener class which must also contain your `jPanel2MouseMoved()` method.