import javax.swing.*; import java.awt.*; //needed to use components setting methods (e.g., colors, fonts) public class VolumePanel extends JPanel { //The is a simple volume slider panel for controlling the volume of //the media player final private static int MINIMUM_VOLUME = 0; final private static int MAXIMUM_VOLUME = 11; final private static int INITIAL_VOLUME = 3; public VolumePanel(int width, int height) { // Create and add a simple JLabel to the panel setLayout(null); //use no layout management setSize(width, height); //set panel size // Make a border around the outside with the given title setBorder(BorderFactory.createTitledBorder("Volume")); int MARGIN = 20; //use this to account for the labelled border JSlider volumeSlider = new JSlider(JSlider.VERTICAL, MINIMUM_VOLUME, MAXIMUM_VOLUME, INITIAL_VOLUME); volumeSlider.setLocation(MARGIN,MARGIN); volumeSlider.setSize(width,height-MARGIN*2); add(volumeSlider); //Turn on labels at major tick marks. volumeSlider.setMajorTickSpacing(5); volumeSlider.setMinorTickSpacing(1); volumeSlider.setPaintTicks(true); volumeSlider.setPaintLabels(true); } }