代码类

1 import java.awt.;
2 import java.util.Date;
3 import javax.swing.
;
4
5 public class Clock extends JComponent{
6 /*
7

8 /
9 private static final long serialVersionUID = -5379472973578609775L;
10 private Font f = new Font("微软雅黑",Font.PLAIN,15);
11 private Font f2 = new Font("微软雅黑",Font.BOLD,15);
12 private JLabel l = new JLabel("当前时间:");
13 private JLabel display = new JLabel();
14 private JLabel display2 = new JLabel("");
15 private int hour = 0;
16 private int min = 0;
17 private int sec = 0;
18 private Date now = new Date();
19 private Graphics2D g;
20 final double PI = Math.PI;
21 private String strTime = "" ;
22
23 @SuppressWarnings("deprecation")
24 public Clock(){
25 add(l);
26 l.setBounds(120, 320, 80, 20);
27 l.setFont(f);
28 add(display);
29 display.setBounds(195, 320, 80, 20);
30 display.setFont(f);
31 display.setBorder(BorderFactory.createLineBorder(Color.black));
32 add(display2);
33 display2.setBounds(90, 350, 250, 20);
34 display2.setFont(f);
35 hour = now.getHours();
36 min = now.getMinutes();
37 sec = now.getSeconds();
38 setVisible(true);
39 }
40
41 public void paintComponent(Graphics g1){
42 double x,y;
43 super.paintComponent(g1);
44 g = (Graphics2D) g1;
45 //反锯齿开关开
46 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
47
48 //画表盘
49 g.setPaint(new GradientPaint(5,40,Color.blue,15,50,Color.yellow,true));
50 g.setStroke( new BasicStroke(3,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL));
51 g.drawOval(75, 40, 250, 250);
52 g.fillOval(195, 160, 10, 10);
53 g.setColor(Color.black);
54
55 //画60个点
56 for(int i = 0;i < 60;i++)
57 {
58 double[] co = new double[2];
59 co = paint_Dot(i
2 * PI / 60);
60 x = co[0];
61 y = co[1];
62 if(i == 0 || i == 15 || i == 30 || i == 45)//画3,6,9,12四个大点
63 {
64 g.fillOval((int)(x - 5 + 200),(int)(y - 5 + 165),10,10);
65 }
66 else//其他小点
67 {
68 g.fillOval((int)(x - 2.5 + 200),(int)(y - 2.5 + 165),5,5);
69 }

转载于:https://blog.51cto.com/14380112/2406939

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值