首页 > 其他 > 详细

16.14

时间:2016-07-08 08:58:03      阅读:238      评论: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_14 extends JFrame{
 8     
 9     public Test_16_14(){
10         add(new ImageP());
11     }
12     public static void main(String[] args) {
13         // TODO Auto-generated method stub
14         Test_16_14 frame = new Test_16_14();
15             frame.setSize(800, 600);
16             frame.setTitle("Test_16_14");
17             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18             frame.setLocationRelativeTo(null); // Center the frame
19             frame.setVisible(true);  
20     }
21     
22     class ImageP extends JPanel{        
23         private ImageIcon imageI = new ImageIcon("image/ca.gif");
24         private Image image = imageI.getImage();
25         private int x;
26         
27         public ImageP(){
28             Timer timer = new Timer(1000,new TimerListener());
29             timer.start();
30         }
31         protected void paintComponent(Graphics g){
32             super.paintComponent(g);
33             
34             if(image != null)
35                 g.drawImage(image, 0, getHeight()-97-x, 193,97,this);
36             x += 10;
37         }
38         
39         class TimerListener implements ActionListener{
40             public void actionPerformed(ActionEvent e) {
41                 // TODO Auto-generated method stub
42                 repaint();
43             }  
44         }
45     }
46 }
Test_16_14.java

效果图:

技术分享

 

16.14

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

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