📄 timerlabel.java
字号:
//package TimerLabel;
import java.awt.*;
public class TimerLabel extends Label implements Runnable{
Label comp;
int timediff;
int CountSecs=0;
int CountMins=0;
String sLabelText=" ";
Thread t;
boolean running=false;
boolean suspended=false;
public TimerLabel(){
super(" ");
t = new Thread(this);
this.setBackground(Color.white);
}//End of constructor
public void StartCount(){
if((running ==false)&& (suspended == false)){
t.start();
running=true;
}
if(suspended==true){
t.resume();
suspended=false;
running=true;
}
}
public void StopCount(){
if(running==true){
t.suspend();
running=false;
suspended=true;
}
}//End of setStopCount
public void Zero(){
StopCount();
CountSecs=0;
sLabelText="123456789";
this.setText(sLabelText);
}//End of setZero
public void run(){
while(true){
try{
CountSecs++;
if(CountSecs == 59){
CountMins++;
sLabelText=sLabelText+CountMins+": ";
CountSecs=0;
}else
{
sLabelText=""+CountMins+":"+CountSecs + " ";
this.validate();
System.out.println(sLabelText);
}
this.setText(sLabelText);
//t.sleep(timediff);
t.yield();
t.sleep(1000);
}catch(Exception e){}
}
}//End of run
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -