?? clock.java
字號:
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Clock extends JFrame implements Runnable{
Date d;
GregorianCalendar gcCalendar;
String strTime;
Thread tClock;
JPanel pnlMain;
JLabel lblClock;
public Clock(){
pnlMain=new JPanel();
lblClock=new JLabel("sdfsdf");
setContentPane(pnlMain);
tClock=new Thread(this);
lblClock.setForeground(Color.red);
lblClock.setFont(new Font("宋體",Font.BOLD,30));
pnlMain.add(lblClock,"Center");
tClock.start();
pack();
setVisible(true);
setResizable(false);
setDefaultCloseOperation(2);
}
public void run(){
while(tClock!=null)
{
d=new Date();
gcCalendar=new GregorianCalendar();
gcCalendar.setTime(d);
String h,m,s;
h=gcCalendar.get(Calendar.HOUR)>9?"":"0";
m=gcCalendar.get(Calendar.MINUTE)>9?"":"0";
s=gcCalendar.get(Calendar.SECOND)>9?"":"0";
String strDate="當前日期:"+gcCalendar.get(Calendar.YEAR)+
"-"+gcCalendar.get(Calendar.MONTH+1)+"-"+
gcCalendar.get(Calendar.DATE);
strTime="當前時間:"+h+gcCalendar.get(Calendar.HOUR)+":"+m+gcCalendar.get(Calendar.MINUTE)+
":"+s+gcCalendar.get(Calendar.SECOND);
lblClock.setText(strDate+"\r\n"+strTime);
try
{
tClock.sleep(1000);
}
catch(InterruptedException ie){JOptionPane.showMessageDialog(null,"線程中斷!");}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -