zoukankan      html  css  js  c++  java
  • Java--下大雪模拟

    package firstpack;
    import java.awt.*;
    
    public class MyStar {
        public static void main(String[] args) {
            Frame w = new Frame();
            w.setSize(800, 700);
            w.setBackground(Color.black);
            
            MyPanel mp = new MyPanel();
            w.add(mp);
            
            Thread t = new Thread(mp);
            t.start();
            
            w.setVisible(true);
        }
    
    }
    
    class MyPanel extends Panel implements Runnable {
        int x[] = new int[300];
        int y[] = new int[300];
        
        //构造方法
        public MyPanel() {
            for(int i=0;i<300;i++) {
                x[i] = (int)(Math.random()*800);
                y[i] = (int)(Math.random()*700);
            }
        }
        
        public void paint(Graphics g) {
                g.setColor(Color.white);
                for(int i=0;i<300;i++) {
                    g.drawString("*", x[i], y[i]);
                }
                
        }
            
        public void run() {
            while(true) {
                try {
                    for(int i=0;i<300;i++) {
                        y[i]++;
                        if(y[i]>700) {
                            y[i] = 0;
                        }
                    }
                    Thread.sleep(10);
                }catch(Exception e) {
                    
                }
                repaint();//重画
            }
            
        }
    }
  • 相关阅读:
    secFox setting
    Xmind settings lower
    Test435678
    Cmd管理员运行
    office install problems
    MSOCache office问题
    WeRun is mini-app
    解决谷歌跨域调试不可用
    xml文件读写
    c++ 矩阵运算库 Eigen等
  • 原文地址:https://www.cnblogs.com/fredkeke/p/7636178.html
Copyright © 2011-2022 走看看