当前位置:   article > 正文

java做的一个时钟的小程序_java编写一个会走的时钟

java编写一个会走的时钟
import java.applet.*;
import java.awt.*;
import java.util.Calendar;
public class Clock extends Applet implements Runnable
{
 // private int xi,yi;
  //private int r;
  Calendar t;
  Thread t1;
  private int s,m,h;
  public void init()
 {
  }
  public void paint(Graphics g)
 {
     g.setColor(Color.red);
     g.drawOval(50,50,100,100);
  g.setColor(Color.black);
     g.fillOval(50,50,102,102);
  g.setColor(Color.blue);
  g.drawOval(48,48,105,105);
  g.drawOval(105,105,5,5);
  g.drawString("12",97,65);
  g.drawLine(100,50,100,55);
  g.drawString("3",140,100);
     g.drawLine(150,100,145,100);
  g.drawString("6",100,140);
  g.drawLine(100,150,100,145);
  g.drawString("9",60,100);
  g.drawLine(50,100,55,100);
     g.setColor(Color.blue);
     t=Calendar.getInstance();
  s=t.get(Calendar.SECOND);
  m=t.get(Calendar.MINUTE);
  h=t.get(Calendar.HOUR);
  g.setColor(Color.green);
  g.drawLine(105,105,105+(int)(40*Math.sin(2*s*Math.PI/60)),105-(int)(40*Math.cos(2*s*Math.PI/60)));
     g.setColor(Color.yellow);
  g.drawLine(105,105,105+(int)(30*Math.sin(2*m*Math.PI/60)),105-(int)(30*Math.cos(2*m*Math.PI/60)));
     g.setColor(Color.red);
 g.drawLine(105,105,105+(int)(20*Math.sin((h*5+m/12)*2*Math.PI/60)),105-(int)(20*Math.cos((h*5+m/12)*2*Math.PI/60)));
     g.drawString("现在的时间是:"+h+":"+m+":"+s,150,150);
 }
  public void run()
 {
    while(true)
  {
    try
    {
  repaint();
  Thread.sleep(1000);
    }
    catch (Exception e)
    {
    }
 
 }
    }
  public void start()
 {
     
  t1=new Thread(this);
  t1.start();
 
  }
 
 }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/268953
推荐阅读
相关标签
  

闽ICP备14008679号