import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Calendar;
public class time11 extends Applet implements Runnable{
private Thread athread;
public void paint(Graphics g){
Calendar c = Calendar.getInstance();
int h=c.get(Calendar.HOUR_OF_DAY);
int m=c.get(Calendar.MINUTE);
int s=c.get(Calendar.SECOND);
int sx,sy ,mx,my,hx,hy;
sx = (int) ((int)60+40*(Math.cos(s*Math.PI/30))-Math.PI/2);
sy = (int) ((int)60+40*(Math.sin(s*Math.PI/30))-Math.PI/2);
mx=(int) ((int)60+45*(Math.cos(m*Math.PI/30))-Math.PI/2);
my=(int) ((int)60+45*(Math.sin(m*Math.PI/30))-Math.PI/2);
hx=(int) ((int)60+35*(Math.cos(h*Math.PI/6))-Math.PI/2);
hy=(int) ((int)60+35*(Math.sin(h*Math.PI/6))-Math.PI/2);
g.drawOval(0,0,120,120);
g.setColor(Color.darkGray);
g.drawString("9",5,65);
g.drawString("3",110,65);
g.drawString("12",55,15);
g.drawString("6",55,115);
g.drawString("1",80,20);
g.drawString("2",100,40);
g.drawString("4",100,90);
g.drawString("5",80,110);
g.drawString("7",30,110);
g.drawString("8",10,90);
g.drawString("10",10,40);
g.drawString("11",30,20);
g.setColor(Color.red);
g.drawLine(60,60,hx,hy);
g.setColor(Color.blue);
g.drawLine(60,60,mx,my);
g.setColor(Color.green);
g.drawLine(60,60,sx,sy);
}
public void start()
{
if(athread == null)
{
athread = new Thread(this);
athread.start();
}
}
public void stop()
{
if(athread != null)
{
athread.interrupt();
athread = null;
}
}
public void run()
{
while(athread != null)
{
repaint();
try
{
athread.sleep(1000);
}
catch(InterruptedException e)
{
}
}
}
/**
* This is the default constructor
*/
public time11() {
super();
}
/**
* This method initializes this
*
* @return void
*/
public void init() {
this.setSize(300, 200);
}
}
------解决方案--------------------
没考虑时区吧
中国是东八区,运行结果正好差8小时