1 package MyTest; 2 3 import java.awt.*; 4 import javax.swing.*; 5 6 public class WhiteSnow { 7 public static void main(String args[]){ 8 JFrame w=new JFrame(); 9 w.setSize(1366,768); 10 w.setBackground(Color.BLACK); 11 12 mypanel13 mp=new mypanel13(); 13 mp.setBackground(Color.BLACK); 14 w.add(mp); 15 16 Thread t1=new Thread(mp); 17 t1.start(); 18 19 w.setVisible(true); 20 } 21 22 } 23 class mypanel13 extends JPanel implements Runnable{ 24 int []x=new int[300]; 25 int []y=new int[300]; 26 27 public mypanel13(){ 28 for(int i=0;i<300;i++){ 29 x[i]=(int)(Math.random()*1366); 30 y[i]=(int)(Math.random()*766); 31 } 32 } 33 34 public void paint(Graphics g){ 35 super.paint(g); 36 g.setColor(Color.WHITE); 37 for(int i=0;i<300;i++){ 38 g.drawString("*", x[i], y[i]); 39 } 40 } 41 public void run(){ 42 while(true){ 43 try{ 44 for(int i=0;i<300;i++){ 45 switch(i%3){ 46 case 0: 47 //x[i]=x[i]+1; 48 y[i]=y[i]+1; 49 break; 50 case 1: 51 //x[i]=x[i]+2; 52 y[i]=y[i]+2; 53 break; 54 case 2: 55 //x[i]=x[i]+3; 56 y[i]=y[i]+3; 57 break; 58 59 } 60 61 y[i]++; 62 if(y[i]>766){ 63 y[i]=0; 64 } 65 } 66 Thread.sleep(20); 67 }catch(Exception e){} 68 repaint(); 69 } 70 } 71 }
时间: 2024-10-13 18:33:10