码迷,mamicode.com
首页 > 其他好文 > 详细

16.15

时间:2016-07-10 12:35:43      阅读:155      评论: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_15 extends JFrame{
 8     
 9     public Test_16_15(){
10         add(new JP());
11     }
12     public static void main(String[] args) {
13         // TODO Auto-generated method stub
14         Test_16_15 frame = new Test_16_15();        
15         frame.setSize(200, 200);
16         frame.setTitle("Test_16_15");
17         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18         frame.setLocationRelativeTo(null); // Center the frame
19         frame.setVisible(true); 
20     }
21     
22     class JP extends JPanel{        
23         private int width ;
24         private int height;
25         private int x = 30 , y = 150;
26 
27         public JP(){
28             Timer timer = new Timer(1000,new TimerListener());
29             timer.start();
30         }
31         protected void paintComponent(Graphics g)
32         {    
33             width = getWidth();
34             height = getHeight();
35             
36             super.paintComponent(g);
37             
38             if(x > width) x = 0;
39             g.fillOval(x + 30, y, 10, 10);
40             g.fillRect(x, y - 10, 50, 10);
41             x += 20;
42         }
43         class TimerListener implements ActionListener{
44 
45             @Override
46             public void actionPerformed(ActionEvent arg0) {
47                 // TODO Auto-generated method stub
48                 repaint();
49             }
50             
51         }
52     }
53 }
Test_16_15.java

如图:

技术分享

 

16.15

标签:

原文地址:http://www.cnblogs.com/wanjiang/p/5657426.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!