首页 > 其他 > 详细

16.12

时间:2016-07-05 22:19:36      阅读:146      评论:0      收藏:0      [点我收藏+]

技术分享

技术分享
 1 import java.awt.*;
 2 import java.awt.event.ActionEvent;
 3 import java.awt.event.ActionListener;
 4 
 5 import javax.swing.*;
 6 
 7 public class Test_16_12 extends JFrame{
 8     
 9     public Test_16_12(){
10         add(new JP());
11     }
12     public static void main(String[] args) {
13         // TODO Auto-generated method stub
14         Test_16_12 t1 = new Test_16_12();
15         t1.setTitle("Test_16.12");
16         t1.setLocationRelativeTo(null);
17         t1.setSize(300,300);
18         t1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
19         t1.setVisible(true);
20     }
21     
22     static class JP extends JPanel{
23         private int h =0;
24         public JP(){
25         Timer timer = new Timer(10,new TimerListener());
26         timer.start();
27         }
28         public void paintComponent(Graphics g){
29             super.paintComponent(g);
30             
31             int xCenter = getWidth()/2;
32             int yCenter = getHeight()/2;
33             int radius = (int)(Math.min(getWidth(), getHeight())*0.4);
34             int x = xCenter - radius;
35             int y = yCenter - radius;
36             
37             
38             g.fillArc(x, y, 2*radius, 2*radius, 0+h, 30);
39             g.fillArc(x, y, 2*radius, 2*radius, 90+h, 30);
40             g.fillArc(x, y, 2*radius, 2*radius, 180+h, 30);
41             g.fillArc(x, y, 2*radius, 2*radius, 270+h, 30);            
42         }
43         class TimerListener implements ActionListener
44         {                
45             @Override
46             public void actionPerformed(ActionEvent arg0) {
47                 // TODO Auto-generated method stub
48                 h += 3;
49                 repaint();
50             }
51         }
52     }
53 }
Test_16_12.java

需要注意的: Timer的创建应该放在JP的构造函数中

技术分享

效果图:下图实际上是动态的

技术分享

 

16.12

原文:http://www.cnblogs.com/wanjiang/p/5645130.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!