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

飘落的雪花

时间:2015-06-09 00:51:10      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

 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 }

技术分享

飘落的雪花

标签:

原文地址:http://www.cnblogs.com/srxhmxx/p/4562245.html

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