?? clock.java
字號:
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class clock extends JFrame implements Runnable
{ Thread clock;
public clock()
{
super("數字時鐘");
setFont(new Font("Times New Raman",Font.BOLD,20));
start();
setSize(120,90);
setLocation(300,50);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void start()
{
if(clock==null){clock=new Thread(this);
clock.start();
}
}
public void run()
{
while(clock!=null)
{ repaint();
try{Thread.sleep(1000);}
catch(InterruptedException ex){ex.printStackTrace();}
}
}
public void stop()
{ clock=null;}
public void paint(Graphics g)
{ Graphics2D g2=(Graphics2D)g;
Calendar now=new GregorianCalendar();
String timeInfo="";
int hour=now.get(Calendar.HOUR_OF_DAY);
int minute=now.get(Calendar.MINUTE);
int second=now.get(Calendar.SECOND);
if(hour<=9)
timeInfo+="0"+hour+":";
else
timeInfo+=hour+":";
if(minute<=9)
timeInfo+="0"+minute+":";
else
timeInfo+=minute+":";
if(second<=9)
timeInfo+="0"+second;
else
timeInfo+=second;
g.setColor(Color.blue);
Dimension dim=getSize();
g.fillRect(0,0,dim.width,dim.height);
g.setColor(Color.cyan);
g.drawString(timeInfo,20,80);
}
public static void main(String[] args){new clock();}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -