Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import java.awt.*;
- /**
- *
- Create a JFrame class called Lab6Part3. Create a JFrame that mimics a volume and balance controller (for an audio system). The maximum volume of the device is 30 and the minimum level is zero, the maximum balance setting is 5 and the minimum balance setting is -5. Supply labels that show the current selected setting for each slider.
- • Create volume slider and add to frame
- • Create balance slider and add to frame
- • Add listeners to the volume slider and test
- • Add listeners to the balance slider and test
- • Create and add Label display of volume setting
- • Create and add Label display of balance setting
- */
- public class Lab7Part3 extends JFrame implements ChangeListener {
- private JLabel labelVolume = new JLabel("Current Volume: ");
- private JLabel labelBalance = new JLabel("Current Balance:");
- //JSlider
- private JSlider sliderVolume = new JSlider();
- private JSlider sliderBalance = new JSlider();
- private Lab7Part3(){
- JPanel thePanel = new JPanel ();
- JPanel thePanel1 = new JPanel ();
- JPanel thePanel2 = new JPanel ();
- //max and min value
- sliderVolume.setMaximum (30);
- sliderVolume.setMinimum (0);
- sliderBalance.setMaximum (5);
- sliderBalance.setMinimum (-5);
- sliderBalance.setValue (0);
- sliderVolume.setValue (0);
- sliderVolume.addChangeListener (this);
- sliderBalance.addChangeListener (this);
- thePanel1.add(sliderBalance);
- thePanel1.add (labelBalance);
- thePanel2.add(sliderVolume);
- thePanel2.add (labelVolume);
- thePanel.add (thePanel1,BorderLayout.NORTH);
- thePanel.add (thePanel2,BorderLayout.CENTER);
- getContentPane ().add (thePanel);
- setSize(500,200);
- setVisible(true);
- }
- public static void main(String[] args) {
- new Lab7Part3 ();
- }
- @Override
- public void stateChanged(ChangeEvent e) {
- labelVolume.setText("Current Volume: " + sliderVolume.getValue());
- labelBalance.setText ("Current Balance: " +sliderBalance.getValue ());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement