满天星Java

贡献者:游客1945579 类别:代码 时间:2016-07-26 16:43:16 收藏数:23 评分:0
返回上页 举报此文章
请选择举报理由:




收藏到我的文章 改错字
package test;
import java.awt.*;
import javax.swing.*;
//import test.DateTime ;
public class test {
public static void main(String args[]) {
JFrame w = new JFrame();
w.setSize(800,600);
w.setBackground(Color.BLACK);
MyPanel mp= new MyPanel();
w.add(mp);
Thread t = new Thread(mp);
t.start();
w.setVisible(true);
}
}
@SuppressWarnings("serial")
class MyPanel extends JPanel implements Runnable {
int x[] = new int[300] ;
int y[] = new int[300] ;
int []h = new int[300] ;
int c[] = new int[300] ;
public MyPanel(){
for(int i = 0; i < 300; i++)
{
x[i] = (int)(Math.random()*800);
y[i] = (int)(Math.random()*600);
h[i] = (int)(Math.random()*30);
c[i] = (int)(Math.random()*255);
}
}
public void paint(Graphics g){
super.paint(g) ;
this.setBackground(Color.black) ;
g.setColor(Color.WHITE) ;
g.fillOval(100, 100, 150, 150) ;
g.setColor(Color.BLACK) ;
g.fillOval(80,80,150,150) ;
for(int i = 0 ; i < 300; i++)
{
g.setColor(new Color(c[i],c[i],255));
Font f = new Font("", Font.BOLD, h[i]);
g.setFont(f) ;
g.drawString("*", x[i], y[i]);
}
}
public void run(){
while(true){
/*DateTime date = new DateTime() ;
String time;
time = date.getTime() ;
System.out.println(time) ;*/
for(int i = 0; i < 300; i++)
{
y[i]++;
if(y[i] % 10 == 0)
c[i] = (int)(Math.random()*255);
if(y[i]>=600)
{
x[i] = (int)(Math.random()*800);
h[i] = (int)(Math.random()*30);
y[i] = 0;
}
}
try{
Thread.sleep(10);
}catch(Exception e){
/*System.out.println(e);*/
}
repaint();
}
}
}
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章热度:
文章难度:
文章质量:
说明:系统根据文章的热度、难度、质量自动认证,已认证的文章将参与打字排名!

本文打字排名TOP20

登录后可见