用applet实现clock问题????????
用applet实现clock,我用一下代码实现,为什么秒针在15,30,45,60 的时候会不显示???
import java.awt.*;
import java.awt.Graphics;
import java.util.Date;
public class ClockDemo
extends java.applet.Applet
implements Runnable
{
Thread my_thread=null;
//-------------------------------------------------
public void start()
{
my_thread=new Thread(this);
my_thread.start();
}
public void run()
{
while(true)
{ repaint();
try {
Thread.sleep(1000);
}
catch(InterruptedException e)
{System.out.println(e);}
}
}
public void stop()
{ my_thread.stop(); }
public void paint(Graphics g)
{ Date timeNow = new Date();
Clock myClock = new Clock(timeNow.getHours(),
timeNow.getMinutes(),
timeNow.getSeconds());
//g.drawString(timeNow,20,20);
//Graphics g= Graphics();
myClock.show(g,100,100,100);
}
}
class Clock
{int hours,minutes,second,radius;
//ClockDemo stop=new ClockDemo();
Clock(int hrs,int min,int sec)
{ hours=hrs%12; minutes=min; second=sec; }
void show(Graphics g, int x, int y,int redius)
{ radius=redius;
int hrs_len=(int)(radius*0.5);
int min_len=(int)(radius*0.7);
int sec_len=(int)(radius*0.85);
double theta;
g.drawOval(x ,y, radius*2, radius*2);
x=x+100;
y=y+100;
//stop.stop();
theta=(double)(hours*60*60+minutes*60+second)/
43200.0*2.0*Math.PI;
drawNiddle(g,Color.blue, x, y, hrs_len, theta);
theta=(double)(minutes*60-second)/3600.0*2.0*Math.PI;
drawNiddle(g,Color.blue, x, y, min_len,theta);
theta=(double)second/60.0*2.0*Math.PI;
drawNiddle(g,Color.red, x, y, sec_len, theta);
}
private void drawNiddle(Graphics g,
Color c, int x, int y, int len, double theta)
{ g.setColor(c);
g.drawLine(x,y,(int)(x+len*Math.sin(theta)),
(int)(y-len*Math.cos(theta)));
}
}