package class2_2_PinballStrategy_start; import java.awt.Color; import javax.swing.JFrame; /** * This class implements a virtual duck pond as a JFrame * window that contains JComponent-derived Ducks. * @author hornick */ public class TableTop extends JFrame { public static final int TABLESIZE =500; // size of the duck pond (width & height) /** * constructor - each call creates a separate TableTop * @param title window title */ public TableTop(String title) { createUI(title); // create the user interface setVisible(true); // make it visible } /** * main UI JFrame initialization - size, title, layout, etc * @param title window title */ private void createUI(String title) { // create the containing window and set its size etc setTitle(title); setSize(TABLESIZE, TABLESIZE); // initial window size setResizable(true); // disallow resizing getContentPane().setBackground( Color.BLUE ); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Configure the content pane for absolute layout getContentPane().setLayout(null); } /** * Adds a Ball (a type of JComponent) to the JFrame's content pane. * @param d reference to a Ball object to be added to the content pane. * @note JFrames maintain in internal List of JComponent-derived elements, * which are automatically displayed whenever the JFrame needs to refresh * itself. Since Ball is a JComponent, the Ball image is automatically * painted in the window. */ public void addBall(Ball d) { getContentPane().add(d); // adds a JComponent to the content pane of this JFrame repaint(); // update the JFrame after the new Ball is added } }