标签:
1 package com.java7.mysnow.main; 2 import java.awt.*; 3 4 public class MySnow { 5 public static void main(String[] args) { 6 Frame w = new Frame(); 7 w.setSize(1024, 768); 8 w.setBackground(new Color(205,240,253)); 9 10 MyPanel mp = new MyPanel(); 11 w.add(mp); 12 13 Thread t = new Thread(mp); 14 t.start(); 15 16 w.show(); 17 } 18 } 19 20 class MyPanel extends Panel implements Runnable { 21 int x[] = new int[300]; 22 int y[] = new int[300]; 23 int fx[] = new int[300]; 24 int fy[] = new int[300]; 25 26 // 构造方法 27 public MyPanel() { 28 for(int i = 0; i < 300; i++) { 29 x[i] = (int)(Math.random() * 1024); 30 y[i] = (int)(Math.random() * 768); 31 fx[i] = (int)(Math.random() * 30); 32 fy[i] = (int)(Math.random() * 30); 33 } 34 } 35 public void paint(Graphics g) { 36 g.setColor(Color.WHITE); 37 for(int i = 0; i < 300; i++) { 38 g.setFont(new Font("", fx[i], fy[i])); 39 g.drawString(".", x[i], y[i]); 40 } 41 } 42 public void run() { 43 while(true) { 44 try { 45 for(int i = 0; i < 300; i++) { 46 y[i]++; 47 if(y[i] > 768) { 48 y[i] = 0; 49 } 50 } 51 Thread.sleep(25); 52 } catch (Exception e) { 53 54 } 55 repaint(); 56 } 57 } 58 }
标签:
原文地址:http://www.cnblogs.com/fatoland/p/4197428.html