資源簡介
1、 點擊“Start”按鈕,計時開始,在按鈕與文本框之間顯示流逝的時間,并在窗口打印開始時間等信息。
2、 “Stop”按鈕計時結束,打印結束時間等信息。
3、 Lap按鈕:打印從開始起流逝的總時間,及單圈時間。
4、 Clear按鈕:清除打印的信息。
5、 Save按鈕:將打印的信息寫到日志文件。
6、 時間精確到毫秒。

代碼片段和文件信息
package?time;
import?java.awt.EventQueue;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.io.BufferedWriter;
import?java.io.File;
import?java.io.FileWriter;
import?java.text.SimpleDateFormat;
import?java.util.Date;
import?javax.swing.JButton;
import?javax.swing.JFileChooser;
import?javax.swing.Jframe;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JScrollPane;
import?javax.swing.JTextArea;
import?javax.swing.SwingConstants;
import?javax.swing.Timer;
import?javax.swing.filechooser.FileSystemView;
public?class?test?{
private?Jframe?frame;
private?JTextArea?logText;
private?JButton?startBtn;
private?JButton?pauseBtn;
private?JButton?stopBtn;
private?JButton?loopsBtn;
private?JButton?saveBtn;
private?JLabel?timeRun;
private?JScrollPane?jslp;
private?int?count?=?0;
//?計時器
Date?now?=?new?Date();
private?actionListenner?al;
Timer?timer?=?new?Timer(1?new?actionListenner(){
public?void?actionPerformed(ActionEvent?e)?{
Date?now2?=?new?Date(now.getTime()?+?2);
now?=?now2;
SimpleDateFormat?formatter?=?new?SimpleDateFormat(“HH:mm:ss:SSS“);
timeRun.setText(formatter.format(now));
}
});
/**
?*?Launch?the?application.
?*/
public?static?void?main(String[]?args)?{
EventQueue.invokeLater(new?Runnable()?{
public?void?run()?{
try?{
test?window?=?new?test();
window.frame.setVisible(true);
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
});
}
/**
?*?Create?the?application.
?*/
public?test()?{
initialize();
}
/**
?*?Initialize?the?contents?of?the?frame.
?*/
private?void?initialize()?{
frame?=?new?Jframe();
frame.setBounds(100?100?450?300);
frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
frame.settitle(“跑不準計時器“);
frame.getContentPane().setLayout(null);
//?顯示計時記錄
logText?=?new?JTextArea();
//logText.setBounds(10?10?422?167);
jslp?=?new?JScrollPane(logText);?//給logText加滾動條
jslp.setBounds(10?10?422?167);
//垂直滾動條總是顯示
//jslp.setVerticalScrollBarPolicy(?JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
frame.getContentPane().add(jslp);
//?開始按鈕
startBtn?=?new?JButton(“\u5F00\u59CB“);
startBtn.setBounds(10?238?75?25);
startBtn.addActionListener(new?actionListenner(){
@Override
public?void?actionPerformed(ActionEvent?e)?{
//?TODO?Auto-generated?method?stub
super.actionPerformed(e);
timer.start();
//?定義控件可用與否
stopBtn.setEnabled(true);
loopsBtn.setEnabled(true);
pauseBtn.setEnabled(true);
}
});
frame.getContentPane().add(startBtn);
//?暫停按鈕
pauseBtn?=?new?JButton(“\u6682\u505C“);
pauseBtn.setBounds(95?238?75?25);
pauseBtn.addActionListener(new?actionListenner(){
@Override
public?void?actionPerformed(ActionEvent?e)?{
//?TODO?Auto-generated?method?stub
super.actionPerformed(e);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????301??2015-06-26?08:51??time\.classpath
?????文件?????????380??2015-06-26?08:51??time\.project
?????文件?????????598??2015-06-26?08:51??time\.settings\org.eclipse.jdt.core.prefs
?????文件????????1101??2015-06-26?09:17??time\bin\time\test$1.class
?????文件?????????772??2015-06-26?09:17??time\bin\time\test$2.class
?????文件?????????942??2015-06-26?09:17??time\bin\time\test$3.class
?????文件?????????905??2015-06-26?09:17??time\bin\time\test$4.class
?????文件????????1656??2015-06-26?09:17??time\bin\time\test$5.class
?????文件????????1421??2015-06-26?09:17??time\bin\time\test$6.class
?????文件????????1624??2015-06-26?09:17??time\bin\time\test$7.class
?????文件?????????898??2015-06-26?09:17??time\bin\time\test$actionListenner.class
?????文件????????3765??2015-06-26?09:17??time\bin\time\test.class
?????文件????????6172??2015-06-26?09:17??time\src\time\test.java
- 上一篇:AirKissDebugger.apk
- 下一篇:java實現csv 轉 xm
l
評論
共有 條評論