public static void main(String[] args) {
new DrawFrame();
}
}
class DrawFrame extends Frame{
static ArrayList points = null;
DrawFrame(){
points = new ArrayList();
setBounds(200,200,500,500);
setLayout(new FlowLayout());
Button reDraw = new Button("重画");
add(reDraw);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
reDraw.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
boolean flag = true;
int x,y;
while(flag){
x = new Random().nextInt(500);
y = new Random().nextInt(500);
points.add(new Point(x,y));
repaint();
if(points.size()>5000)
flag = false;
}
}
});
}
public void paint(Graphics g){
int red,green,blue;
Iterator i = points.iterator();
while(i.hasNext()){
Point point = (Point)i.next();
red = new Random().nextInt(255);
green = new Random().nextInt(255);
blue = new Random().nextInt(255);
g.setColor(new Color(red,green,blue));
g.fillOval(point.x, point.y, 15,15); //这里的 point.x和point.y是同时从ArrayList中取出来,同时画 ?
}
}
} 作者: 谭立文 时间: 2012-10-7 14:57 本帖最后由 谭立文 于 2012-10-7 15:13 编辑