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 }