我正在尝试用Java制作秒表并取得了一些成功。如果我这样做,它将打印到shell
System.out.println(min+":"+sec+":"+millisec);
但是,如果我这样做
timerLbl.setText(min+":"+sec+":"+millisec);
public class rubiksTimer extends javax.swing.JFrame {
static int scrambleImage = 1;
static int timesImage = 1;
static int start = 0;
static int stop1 =0;
static int millisec =0;
static int sec =0;
static int min =0;
static int press =1;
Timer timer = new Timer();
TimerTask task = new TimerTask(){
public void run() {
millisec++;
if (millisec>9) {
millisec = 0;
sec++;
}
if (sec>59){
sec=0;
min++;
}
timerLbl.setText(min+":"+sec+":"+millisec);
}
};
public void start(){
timer.scheduleAtFixedRate(task,1000,100);
}