import java.applet.Applet;
import java.awt.*;
import java.util.*;
public class Clock extends Applet implements Runnable{
int x=100,y=100,r=60;
Thread timer=null;
public void init()
{ setBackground(Color.white);
}
public void paint(Graphics g)
{ Date date=new Date();
int h=date.getHours();
int m=date.getMinutes();
int s=date.getSeconds();
g.setColor(Color.blue);
g.drawOval(x-r,y-r,2*r,2*r);
g.setColor(Color.red);
g.drawLine(x,y,(int)(x+0.8*r*Math.sin(s*3.14/30)),(int)(y-0.8*r*Math.cos(s*3.14/30)));
g.setColor(Color.blue);
g.drawLine(x,y,(int)(x+0.6*r*Math.sin(m*3.14/30)),(int)(y-0.6*r*Math.cos(m*3.14/30)));
g.setColor(Color.black);
g.drawLine(x,y,(int)(x+0.5*r*Math.sin(h*3.14/6)),(int)(y-0.5*r*Math.cos(h*3.14/6)));
}
public void start()
{ if(timer==null){Thread timer=new Thread(this);timer.start(); }
}
public void stop()
{
try{
timer.stop();}catch(Exception ae){}
timer=null;
}
public void run()
{while(true)
{repaint();
try{
Thread.sleep(1000); }catch(Exception e){}
}}}
import java.awt.*;
import java.util.*;
public class Clock extends Applet implements Runnable{
int x=100,y=100,r=60;
Thread timer=null;
public void init()
{ setBackground(Color.white);
}
public void paint(Graphics g)
{ Date date=new Date();
int h=date.getHours();
int m=date.getMinutes();
int s=date.getSeconds();
g.setColor(Color.blue);
g.drawOval(x-r,y-r,2*r,2*r);
g.setColor(Color.red);
g.drawLine(x,y,(int)(x+0.8*r*Math.sin(s*3.14/30)),(int)(y-0.8*r*Math.cos(s*3.14/30)));
g.setColor(Color.blue);
g.drawLine(x,y,(int)(x+0.6*r*Math.sin(m*3.14/30)),(int)(y-0.6*r*Math.cos(m*3.14/30)));
g.setColor(Color.black);
g.drawLine(x,y,(int)(x+0.5*r*Math.sin(h*3.14/6)),(int)(y-0.5*r*Math.cos(h*3.14/6)));
}
public void start()
{ if(timer==null){Thread timer=new Thread(this);timer.start(); }
}
public void stop()
{
try{
timer.stop();}catch(Exception ae){}
timer=null;
}
public void run()
{while(true)
{repaint();
try{
Thread.sleep(1000); }catch(Exception e){}
}}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货