// SliderDemoX2.java // Uses JSliders to size a circle // import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class SliderDemoX2 extends JApplet { private Container c; private JSlider width, height; private OvalPanelX2 myPanel; public void init( ) { c = getContentPane( ); myPanel = new OvalPanelX2( ); myPanel.setBackground( Color.red ); width = new JSlider( SwingConstants.HORIZONTAL, 0, 900, 10 ); width.setMajorTickSpacing( 100 ); width.setMinorTickSpacing( 20 ); width.setPaintTicks( true ); width.addChangeListener( new ChangeListener( ) { public void stateChanged( ChangeEvent e ) { myPanel.setWidth( width.getValue( ) ); } } ); height = new JSlider( SwingConstants.VERTICAL, 0, 600, 10 ); height.setMajorTickSpacing( 100 ); height.setMinorTickSpacing( 20 ); height.setPaintTicks( true ); height.addChangeListener( new ChangeListener( ) { public void stateChanged( ChangeEvent e ) { myPanel.setHeight( height.getValue( ) ); } } ); c.add( width, BorderLayout.SOUTH ); // adds the JSlider c.add( height, BorderLayout.EAST ); // adds the JSlider c.add( myPanel, BorderLayout.CENTER ); // adds the drawing panel } }