码迷,mamicode.com
首页 > 其他好文 > 详细

练习.下大雪

时间:2015-01-01 19:44:14      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!