新手绘图多线程问题
package cn.GUI;
import java.awt.*;
import java.util.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestPrintFrame {
public static void main(String[] args) {
new PaintFrame().launchFrame();
}
}
class PaintFrame extends Frame{
private Image iBuffer;
private Graphics gBuffer;
int a = 50;
int b = 50;
int c = 300;
int d = 200;
ArrayList<Point> points = null;
public void launchFrame(){
points = new ArrayList();
for(int i=0;i<500;i++){
points.add(new Point((int)(Math.random()*1000),(int)(Math.random()*1000)));
}
setBounds(300, 20, 1000,700 );
setBackground(Color.black);
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
setVisible(false);
System.exit(0);
}
});
while(true){
a = a+10;
b = b+10;
c = c+10;
d = d+10;
repaint();
try{
Thread.sleep(30);
}catch(InterruptedException e){
}
if(b == 700){
a= 50;
b = 50;
}
if(d == 700){
c= 300;
d = 200;
}
}
}
public void paint(Graphics g){
Iterator<Point> i = points.iterator();
Color e = g.getColor();
g.setColor(Color.white);
g.fillOval(700,150,150,150);
g.setColor(Color.black);
g.fillOval(650, 150, 150, 150);
g.setColor(Color.white);
while(i.hasNext()){
Point p = i.next();
g.drawString("*",p.x,p.y);
}
g.drawLine(a, b, a-40, b-40);
g.drawLine(c, d, c-40, d-40);
g.setColor(e);
}
public void update(Graphics scr) {
if(iBuffer==null) {
iBuffer=createImage(this.getSize().width,this.getSize().height);
gBuffer=iBuffer.getGraphics();
}
gBuffer.setColor(getBackground());
gBuffer.fillRect(0,0,this.getSize().width,this.getSize().height);
paint(gBuffer);
scr.drawImage(iBuffer,0,0,this);
}
}
class Meteor implements Runnable{
public void run() {
}
}
用多线程画多个流星怎么实现
补充:Java , Java SE