标签:
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
public class MySnow extends JFrame {
public MySnow(){
Snow s=new Snow();
Thread t=new Thread(s);
t.start();
this.add(s);
this.setResizable(false);
this.setSize(1366,768);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
MySnow ms=new MySnow();
ms.setVisible(true);
}
}
class Snow extends JPanel implements Runnable{
private int[] x;
private int[] y;
public Snow(){
x=new int[300];
y=new int[300];
this.setBackground(Color.BLACK);
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.WHITE);
g.setFont(new Font("楷体",Font.BOLD,30));
for(int i=0;i<300;i++){
x[i]=(int)(Math.random()*1366);
y[i]=(int)(Math.random()*768);
}
for(int i=0;i<300;i++){
g.drawString("*", x[i], y[i]);
}
}
public void run(){
while(true){
for(int i=0;i<300;i++){
y[i]++;
if(y[i]>768){
y[i]=0;
}
}
try{
Thread.sleep(800);
}catch(Exception e){
}
this.repaint();
}
}
}
标签:
原文地址:http://www.cnblogs.com/YP-W-Ricardo/p/4253958.html