// GrowingCubePanelTester.java // Graphics Demo // APPLET CODE="GrowingCubePanelTester" HEIGHT=480 WIDTH=400 // A cube that contracts up to a point and then expands as a button is pushed // Cube is drawn as an outline - it is not filled import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GrowingCubePanelTester extends JApplet implements ActionListener { int w; int growFactor; Container c; // GUI Components JPanel pGUI; GrowingCubePanel pD; JButton b; public void init( ) { w = 200; // width of the cube growFactor = 10; c = getContentPane( ); pGUI = new JPanel( ); pGUI.setLayout( new FlowLayout( ) ); b = new JButton( "Push" ); b.addActionListener( this ); pGUI.add( b ); pD = new GrowingCubePanel( ); c.add( pGUI, BorderLayout.NORTH ); c.add( pD, BorderLayout.CENTER ); pD.drawInfo( w ); } public void actionPerformed( ActionEvent e ) { if ( w >= 200 || w <= 20 ) growFactor *= -1; // reverse direction w += growFactor; // incr or decr size pD.drawInfo( w ); // pass size to JPanel to draw } }