?? returntime.java
字號:
package notepad;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class ReturnTime extends Frame {
/**
*
*/
private static final long serialVersionUID = 1L;
Button btnClock;
public static Label lblClock;
String strInput;
// TextField txtClock;
public ReturnTime() {
MyEvent me = new MyEvent();
lblClock = new Label("請點擊'設置'按鈕",Label.CENTER);
btnClock = new Button("設置");
btnClock.addActionListener(me);
this.add(lblClock, "Center");
this.add(btnClock, "South");
this.pack();
setTitle("倒計時表");
this.setVisible(true);
this.setResizable(false);
addWindowListener(me);
}
public static void main(String[] args) {
new ReturnTime();
}
}
class MyEvent extends WindowAdapter implements ActionListener {
String strIn;
ThreadTime tt;
public void actionPerformed(ActionEvent ae) {
tt = new ThreadTime(60);
Thread thread = new Thread(tt);
thread.start();
}
public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
class ThreadTime implements Runnable {
long time, start, end;
boolean running=true;
public ThreadTime(int strIn) {
time = (long)(strIn*60000);
end = time + new Date().getTime();
}
public void run() {
while (true) {
start = end - (new Date().getTime());
if (start > 0) {
String strTime = this.convert(start);
ReturnTime.lblClock.setText(strTime);
try {
Thread.sleep(10);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
} else
break;
}
}
public String convert(long ctime) {
long h = ctime / 3600000;
long m = (ctime % 3600000)/ 60000;
long s = (ctime % 60000) / 1000;
long n = (ctime % 1000)/10;
String hh = h < 10 ? "0" : "";
String mm = m < 10 ? "0" : "";
String ss = s < 10 ? "0" : "";
String nn = n < 10 ? "0" : "";
String strTime = hh +h+ ":" + mm +m+ ":" + ss +s+ ":" + nn+n;
return strTime;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -