corejava第10版
This commit is contained in:
1 parent
2021c3c227
commit
6165543dd3
1088 files changed
+94411
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package bounceThread;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* The component that draws the balls.
|
||||
* @version 1.34 2012-01-26
|
||||
* @author Cay Horstmann
|
||||
*/
|
||||
public class BallComponent extends JComponent
|
||||
{
|
||||
private static final int DEFAULT_WIDTH = 450;
|
||||
private static final int DEFAULT_HEIGHT = 350;
|
||||
|
||||
private java.util.List<Ball> balls = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Add a ball to the panel.
|
||||
* @param b the ball to add
|
||||
*/
|
||||
public void add(Ball b)
|
||||
{
|
||||
balls.add(b);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
for (Ball b : balls)
|
||||
{
|
||||
g2.fill(b.getShape());
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); }
|
||||
}
|
||||
Reference in new issue
Block a user