zoukankan      html  css  js  c++  java
  • 16.15

     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_15 extends JFrame{
     8     
     9     public Test_16_15(){
    10         add(new JP());
    11     }
    12     public static void main(String[] args) {
    13         // TODO Auto-generated method stub
    14         Test_16_15 frame = new Test_16_15();        
    15         frame.setSize(200, 200);
    16         frame.setTitle("Test_16_15");
    17         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    18         frame.setLocationRelativeTo(null); // Center the frame
    19         frame.setVisible(true); 
    20     }
    21     
    22     class JP extends JPanel{        
    23         private int width ;
    24         private int height;
    25         private int x = 30 , y = 150;
    26 
    27         public JP(){
    28             Timer timer = new Timer(1000,new TimerListener());
    29             timer.start();
    30         }
    31         protected void paintComponent(Graphics g)
    32         {    
    33             width = getWidth();
    34             height = getHeight();
    35             
    36             super.paintComponent(g);
    37             
    38             if(x > width) x = 0;
    39             g.fillOval(x + 30, y, 10, 10);
    40             g.fillRect(x, y - 10, 50, 10);
    41             x += 20;
    42         }
    43         class TimerListener implements ActionListener{
    44 
    45             @Override
    46             public void actionPerformed(ActionEvent arg0) {
    47                 // TODO Auto-generated method stub
    48                 repaint();
    49             }
    50             
    51         }
    52     }
    53 }
    Test_16_15.java

    如图:

  • 相关阅读:
    区块链技术驱动金融.mobi
    ProcessExplorer 工具下载
    免费的论文查重网站
    接口可以继承接口吗?
    比较中的自动拆装箱
    Java语言中的异常处理
    Java类加载过程
    通过反射访问父类的私有成员
    final关键字详解
    MVC 控制台 +log4net 存入数据库
  • 原文地址:https://www.cnblogs.com/wanjiang/p/5657426.html
Copyright © 2011-2022 走看看