// SliderDemo.java // Uses JSliders to size a circle // import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class SliderDemo extends JApplet { private Container c; private JSlider diameter; private OvalPanel myPanel; public void init( ) { c = getContentPane( ); myPanel = new OvalPanel( ); myPanel.setBackground( Color.yellow ); diameter = new JSlider( SwingConstants.HORIZONTAL, 0, 200, 10 ); diameter.setMajorTickSpacing( 10 ); diameter.setPaintTicks( true ); diameter.addChangeListener( new ChangeListener( ) { public void stateChanged( ChangeEvent e ) { myPanel.setDiameter( diameter.getValue( ) ); } } ); c.add( diameter, BorderLayout.SOUTH); // adds the JSlider c.add( myPanel, BorderLayout.CENTER ); // adds the drawing panel } }