java计时器

java计时器,第1张

你要是想要个计时器,我给你,你的代码看着实在是累人。
import javaawtFlowLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javatextSimpleDateFormat;
import javautilDate;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingTimer;
public class Test extends JFrame{
JLabel lbl=new JLabel();
Date now=new Date();
public Test() {
nowsetHours(0);
nowsetMinutes(0);
nowsetSeconds(0);
Timer timer=new Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent e) {
Date now2=new Date(nowgetTime()+1000);
now=now2;
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
lblsetText(formatterformat(now));
}
});
timerstart();
thissetLayout(new FlowLayout());
thisadd(lbl);
thissetSize(300,200);
thissetVisible(true);
}
public static void main(String[] args) {
Test t=new Test();
}
}

/ 每3秒运行一次 /
Timer timer = new Timer();
TimerTask tt = new TimerTask() {
public void run() {
/ 投放炸d的 *** 作 /
new Thread() {
public void run() {
try {
Threadsleep(5000);
}catch (Exception e) { }
/ 爆炸的 *** 作 /
}
}start();
}
}; timerschedule(tt, 0, 3000);

package chaper5;
import javaawtFont;
import javaawtHeadlessException;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaawteventKeyEvent;
import javaxswingJButton;
import javaxswingAbstractButton;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJOptionPane;
import lx11Clock;
public class TestClock extends JFrame implements ActionListener{
/
@param args
/
Thread t;
Clock label_1 = new Clock(0,1,0);
int h,m,s;boolean bz=true;
public TestClock() {
super();
getContentPane()setLayout(null);
final JLabel label = new JLabel();
labelsetFont(new Font("", FontBOLD, 18));
labelsetBounds(71, 75, 84, 34);
labelsetText("倒计时:");
getContentPane()add(label);
label_1setBounds(145, 75, 167, 34);
label_1setFont(new Font("", FontBOLD, 15));
getContentPane()add(label_1);
final JButton button = new JButton();
buttonsetFont(new Font("", FontPLAIN, 15));
buttonsetText("开始");
buttonsetBounds(135, 140, 99, 23);
getContentPane()add(button);
buttonaddActionListener(this);
thissetSize(400, 400);
thissetVisible(true);
}
public static void main(String[] args) {
// TODO 自动生成方法存根
new TestClock();
}
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
label_1bz=true;label_1h=0;label_1m=1;label_1s=0;
t=new Thread(label_1); tstart();
}
public void actionPerformed1(ActionEvent e){
int spendTime = 0;
int i = spendTime++;
int showTime =1-spendTime;
AbstractButton label = null;
labelsetText("倒计时:");
}
public void keyReleased(KeyEvent e){
PersonInMaze person=(PersonInMaze)egetSource();
int m=-1,n=-1;
MazePoint endPoint=persongetAtMazePoint();
if(endPointgetWallOrRoad()getIsOut()){
Thread recordTime = null;
recordTimestop();
JOptionPaneshowMessageDialog(this,"您成功了!","消息框",
JOptionPaneINFORMATION_MESSAGE );
}
}
public void keyTyped(KeyEvent e) {}
}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13159021.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-06-13
下一篇 2023-06-13

发表评论

登录后才能评论

评论列表(0条)

保存