Biblioteca Java - Rev 27

Subversion Repositories:
Rev:
package ex2_balls;
import java.awt.*;
import javax.swing.*;
import java.util.*;

public class BallWorld extends JPanel {

    private final int xSize = 250;
    private final int ySize = 250;

    private final static Color BGCOLOR   = Color.white;

    private ArrayList balls = new ArrayList();

    public BallWorld() {
        setPreferredSize(new Dimension(xSize,ySize));
        setOpaque(true);
        setBackground(BGCOLOR);
    }

 
    public void addBall(final Ball b) {
        SwingUtilities.invokeLater(new Runnable () {
                public void run() {
                    balls.add(b);
                }
            });
    }


    public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Iterator i = balls.iterator();
                while (i.hasNext()) ((Ball)i.next()).draw(g);
    }

}