该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test4 {
@SuppressWarnings("deprecation")
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame w = new JFrame();
w.setSize(1366, 768);
w.setBackground(Color.BLACK);
MyPanel3 mp = new MyPanel3();
w.add(mp);
Thread t = new Thread(mp);
t.start();
w.show();
}
}
@SuppressWarnings("serial")
class MyPanel3 extends JPanel implements Runnable{
int x[] = new int[300];
int y[] = new int[300];
//构造方法
public MyPanel3(){
for(int i = 0;i < 300;i++){
x[i] = (int)(Math.random()*1366);
y[i] = (int)(Math.random()*768);
}
}
public void paint(Graphics g){
g.setColor(Color.WHITE);
for(int i =0;i < 300;i++ ){
g.drawString("*", x[i], y[i]);
}
}
public void run(){
while(true){
try{
for(int i = 0;i < 300;i++){
y[i]++;
if(y[i]>768){
y[i]=0;
}
}
Thread.sleep(30);
}catch(Exception e){}
repaint();
}
}
}