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 }
  • 相关阅读:
    document
    reg() replace
    BOM和DOM的区别
    注册表
    实现移动端通过下拉菜单栏实现pc端的导航栏
    通过ajax获取api,并且通过jquery获取自定义属性
    git的使用
    当盒子不设置width,而设置max-width遇到的问题
    CSS之position
    JavaScript之数组常用的方法
  • 原文地址:https://www.cnblogs.com/sdrzlyz/p/3439572.html
Copyright © 2011-2022 走看看