zoukankan      html  css  js  c++  java
  • Repaint轨迹保留?(待处理,待编辑)

     1 import java.awt.Color;
     2 import java.awt.Graphics;
     3 
     4 import javax.swing.JFrame;
     5 import javax.swing.JPanel;
     6 
     7 
     8 public class SimpleAnimation {
     9 
    10     /**
    11      * @param args
    12      */
    13     int x=0,y=0;
    14     public static void main(String[] args) {
    15         // TODO Auto-generated method stub
    16         SimpleAnimation gui=new SimpleAnimation();
    17         gui.test();
    18     }
    19     public void test() {
    20         JFrame frame=new JFrame();
    21         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    22         
    23         MyDrawPanel drawPanel=new MyDrawPanel();
    24         
    25         frame.getContentPane().add(drawPanel);
    26         frame.setSize(500, 500);
    27         frame.setVisible(true);
    28         
    29         for (int i = 0; i < frame.getHeight()-60; i++) {
    30             x++;
    31             y++;
    32             drawPanel.repaint();
    33             try {
    34                 Thread.sleep((int)(Math.random()*140));
    35             } catch (Exception ex) {
    36                 // TODO: handle exception
    37                 ex.printStackTrace();
    38             }
    39         }
    40     }
    41     class MyDrawPanel extends JPanel{
    42         public void paintComponent(Graphics g) {
    43             int red=(int)(Math.random()*255);
    44             int green=(int)(Math.random()*255);
    45             int blue=(int)(Math.random()*255);
    46             g.setColor(Color.red);
    47             g.fillRect(0, 0, this.getWidth(), this.getHeight());
    48             g.setColor(new Color(red,green,blue));
    49             g.fillOval(x, y, 40, 40);
    50         }
    51     }
    52 
    53 }
  • 相关阅读:
    UNIX 高手的另外 10 个习惯
    python中的cls到底指的是什么
    一篇文章搞懂Python装饰器所有用法
    sysbench 压测
    python面向对象进阶
    python 学生表
    搞懂蓝绿发布、灰度发布和滚动发布
    数据库之视图、索引
    Java内存模型(JMM)以及 垃圾回收机制 小结
    Java线程唤醒与阻塞
  • 原文地址:https://www.cnblogs.com/sdrzlyz/p/3439572.html
Copyright © 2011-2022 走看看