Biblioteca Java - Blame information for rev 27
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
27 | mihai | 1 | package ex2_balls; |
2 | import java.awt.*; | ||
3 | import javax.swing.*; | ||
4 | import java.util.*; | ||
5 | |||
6 | public class BallWorld extends JPanel { | ||
7 | |||
8 | private final int xSize = 250; | ||
9 | private final int ySize = 250; | ||
10 | |||
11 | private final static Color BGCOLOR = Color.white; | ||
12 | |||
13 | private ArrayList balls = new ArrayList(); | ||
14 | |||
15 | public BallWorld() { | ||
16 | setPreferredSize(new Dimension(xSize,ySize)); | ||
17 | setOpaque(true); | ||
18 | setBackground(BGCOLOR); | ||
19 | } | ||
20 | |||
21 | |||
22 | public void addBall(final Ball b) { | ||
23 | SwingUtilities.invokeLater(new Runnable () { | ||
24 | public void run() { | ||
25 | balls.add(b); | ||
26 | } | ||
27 | }); | ||
28 | } | ||
29 | |||
30 | |||
31 | public void paintComponent(Graphics g) { | ||
32 | super.paintComponent(g); | ||
33 | Iterator i = balls.iterator(); | ||
34 | while (i.hasNext()) ((Ball)i.next()).draw(g); | ||
35 | } | ||
36 | |||
37 | } | ||
38 |