标签:
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 }
效果图:
标签:
原文地址:http://www.cnblogs.com/wanjiang/p/5652143.html