// // FILE: MultiBallWorldFrame.java // AUTHOR: Eugene Wallingford // DATE: 2012/10/11 // COMMENT: a frame with a bunch of moving balls and a button // that causes the balls to move // // MODIFIED: 2012/10/25 -- Eugene Wallingford // CHANGE : modified to use a MultiBallWorldPanel // import java.awt.Button; import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.GridLayout; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MultiBallWorldFrame extends Frame { private static final int FrameWidth = 600; private static final int FrameHeight = 400; private static final Color[] BallColor = { Color.green, Color.blue, Color.cyan, Color.gray, Color.black, Color.magenta, Color.red, Color.orange, Color.yellow }; public MultiBallWorldFrame( Color ballColor ) { super(); setSize ( FrameWidth*3, FrameHeight*3 ); setTitle( "Eight Ball Worlds and a Button" ); //***** setLayout( new GridLayout(3, 3) ); for (int i = 0; i < 4; i++) //***** add( new MultiBallWorldPanel( BallColor[i] ) ); Button quitButton = new Button( "QUIT" ); quitButton.addActionListener( new QuitButtonListener() ); add( quitButton ); for (int i = 0; i < 4; i++) add( new MultiBallWorldPanel( BallColor[i] ) ); } public void paint( Graphics g ) { // nothing needed } private class QuitButtonListener implements ActionListener { public void actionPerformed( ActionEvent e ) { System.exit( 0 ); } } }