标签:io color ar java for on art ad ef
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MyStar {
static Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
public static void main(String[] args) {
JFrame star=new JFrame("MyStarKey");
MyPanel mp=new MyPanel();
Thread th=new Thread(mp);
th.start();
star.setBackground(Color.black);
star.setSize(screen);
star.add(mp);
star.show();
}
}
class MyPanel extends JPanel implements Runnable{
static Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
public void paint(Graphics g){
//super.paint(g);
//repaint();
g.setColor(Color.black);
g.fillRect(0, 0, (int)screen.getWidth(), (int)screen.getHeight());
g.setColor(Color.white);
g.fillOval(900, 100, 150, 150);
g.setColor(Color.black);
g.fillOval(860, 70, 150, 150);
g.setColor(Color.white);
for(int i=0;i<400;i++){
g.drawString("*", (int)(Math.random()*screen.getWidth()), (int)(Math.random()*screen.getHeight()));
}
g.setColor(Color.white);
}
@Override
public void run() {
try {
for(int i=0;;i++){
Thread.sleep(1000);
repaint();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
看到达内来演讲后,自己做的一个夜空程序,一闪一闪的星星和月亮
标签:io color ar java for on art ad ef
原文地址:http://www.cnblogs.com/jamsbwo/p/4100203.html