zoukankan      html  css  js  c++  java
  • 16.16

     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
  • 相关阅读:
    [ARC117F]Gateau
    [ARC117D]Miracle Tree
    [loj3504]支配
    [gym102511K]Traffic Blights
    [loj3501]图函数
    [loj3503]滚榜
    [loj3500]矩阵游戏
    [loj2135]幻想乡战略游戏
    [cf720D]Slalom
    [cf1349E]Slime and Hats
  • 原文地址:https://www.cnblogs.com/wanjiang/p/5657462.html
Copyright © 2011-2022 走看看