1 PackageMyTest;2 3 Importjava.awt.*;4 Importjavax.swing.*;5 6 Public classWhitesnow {7 Public Static voidMain (String args[]) {8JFrame w=NewJFrame ();9W.setsize (1366,768);Ten W.setbackground (color.black); One AMypanel13 mp=Newmypanel13 (); - Mp.setbackground (color.black); - W.add (MP); the -Thread t1=NewThread (MP); - T1.start (); - +W.setvisible (true); - } + A } at classMypanel13extendsJPanelImplementsrunnable{ - int[]x=New int[300]; - int[]y=New int[300]; - - PublicMypanel13 () { - for(inti=0;i<300;i++){ inX[i]= (int) (Math.random () *1366); -Y[i]= (int) (Math.random () *766); to } + } - the Public voidPaint (Graphics g) { * Super. Paint (g); $ G.setcolor (color.white);Panax Notoginseng for(inti=0;i<300;i++){ -g.DrawString ("*", X[i], y[i]); the } + } A Public voidrun () { the while(true){ + Try{ - for(inti=0;i<300;i++){ $ Switch(i%3){ $ Case0: - //x[i]=x[i]+1; -Y[i]=y[i]+1; the Break; - Case1:Wuyi //x[i]=x[i]+2; theY[i]=y[i]+2; - Break; Wu Case2: - //x[i]=x[i]+3; AboutY[i]=y[i]+3; $ Break; - - } - Ay[i]++; + if(y[i]>766){ theY[i]=0; - } $ } theThread.Sleep (20); the}Catch(Exception e) {} the repaint (); the } - } in}
The Falling Snowflakes