?? applet1.java
字號(hào):
import java.awt.*;
import java.applet.*;
import java.util.Date;
public class Applet1 extends Applet implements Runnable
{
Date timenow;
Clock myClock;
Thread clockthread=null;
public void start()
{
if (clockthread==null)
{
clockthread=new Thread (this);
clockthread.start();
}
}
public void stop()
{
clockthread.stop();
clockthread=null;
}
public void run()
{
while(true)
{
repaint();
try{Thread.sleep(1000);}
catch(InterruptedException e){}
}
}
public void paint(Graphics g)
{
timenow=new Date();
myClock=new Clock(timenow.getHours (),
timenow.getMinutes (),
timenow.getSeconds ());
g.drawString(timenow.toString(),25,240);
myClock.show(g,100,100,100);
}
}
class Clock
{
Clock(int hrs,int min,int sec)
{
hour=hrs%12;
minute=min;
second=sec;
}
void show(Graphics g,int cx,int cy,int rad)
{
int hrs_len=(int)(rad*0.5),
min_len=(int)(rad*0.6),
sec_len=(int)(rad*0.9);
double theta;
//畫出鐘面
g.drawOval(cx-rad,cy-rad,rad*2,rad*2);
//畫出時(shí)鐘
theta=(double)(hour*60*60+minute*60+second)/43200.0*2.0*Math.PI ;
drawNiddle(g,Color.blue,cx,cy,hrs_len,theta);
//
theta=(double)(minute*60+second)/3600.0*2.0*Math.PI ;
drawNiddle(g,Color.red,cx,cy,sec_len,theta);
//
theta=(double)(second)/60.0*2.0*Math.PI ;
drawNiddle(g,Color.green ,cx,cy,sec_len,theta);
}
private void drawNiddle(Graphics g,Color c,int x,int y,int len,double theta)
{
int ex=(int)(x+len*Math.sin(theta));
int ey=(int)(y-len*Math.cos(theta));
g.setColor (c);
g.drawLine(x,y,ex,ey);
}
int hour,minute,second;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -