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

16.16

时间:2016-07-10 13:56:35      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享
 1 import java.awt.Graphics;
 2 import java.awt.event.ActionEvent;
 3 import java.awt.event.ActionListener;
 4 
 5 import javax.swing.*;
 6 
 7 
 8 
 9 public class Test_16_16 extends JFrame{
10     
11     public Test_16_16(){
12         add(new JP());
13     }
14     public static void main(String[] args) {
15         // TODO Auto-generated method stub
16         Test_16_16 frame = new Test_16_16();        
17         frame.setSize(300,220);
18         frame.setTitle("Test_16_16");
19         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20         frame.setLocationRelativeTo(null); // Center the frame
21         frame.setVisible(true); 
22     }
23     
24     static class JP extends JPanel{
25         private boolean visi = true;
26         
27         public JP(){
28             Timer timer = new Timer(1000,new TimerListener());
29             timer.start();
30         }
31         protected void paintComponent(Graphics g){
32             super.paintComponent(g);
33             if(visi == true)
34                 g.drawImage(new ImageIcon("image/flag4.gif").getImage(), 0, 0, this);
35         }
36         class TimerListener implements ActionListener{
37 
38             @Override
39             public void actionPerformed(ActionEvent arg0) {
40                 // TODO Auto-generated method stub
41                 if(visi == true) visi = false;
42                 else visi = true;
43                 repaint();
44             }
45             
46         }
47     }
48 }
Test_16_16.java

 

16.16

标签:

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

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