1 PackageCom.java7.mysnow.main;2 Importjava.awt.*;3 ImportJavax.swing.JFrame;4 ImportJavax.swing.JPanel;5 6 Public classMysnow {7 Public Static voidMain (string[] args) {8Frame W =NewJFrame ();9W.setsize (1024, 768);Ten OneMypanel MP =NewMypanel (); A W.add (MP); - -Thread T =NewThread (MP); the T.start (); - -W.setvisible (true); - } + } - + classMypanelextendsJPanelImplementsRunnable { A intX[] =New int[300]; at intY[] =New int[300]; - intFx[] =New int[300]; - intFy[] =New int[300]; - - //Construction Method - PublicMypanel () { in for(inti = 0; I < 300; i++) { -X[i] = (int) (Math.random () * 1024); toY[i] = (int) (Math.random () * 768); +Fx[i] = (int) (Math.random () * 30); -Fy[i] = (int) (Math.random () * 30); the } * } $ Public voidPaint (Graphics g) {Panax Notoginseng Super. Paint (g); - This. SetBackground (NewColor (205,240,253)); the G.setcolor (color.white); + for(inti = 0; I < 300; i++) { AG.setfont (NewFont ("", Fx[i], fy[i]); theg.DrawString (".", X[i], y[i]); + } - } $ Public voidrun () { $ while(true) { - Try { - for(inti = 0; I < 300; i++) { they[i]++; - if(Y[i] > 768) {WuyiY[i] = 0; the } - } WuThread.Sleep (25); -}Catch(Exception e) { About $ } - repaint (); - } - } A}
Practice. Under the heavy snow