Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import javax.swing.*;
  2. import javax.swing.event.ChangeEvent;
  3. import javax.swing.event.ChangeListener;
  4. import java.awt.*;
  5.  
  6. /**
  7. *
  8. 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.
  9. • Create volume slider and add to frame
  10. • Create balance slider and add to frame
  11. • Add listeners to the volume slider and test
  12. • Add listeners to the balance slider and test
  13. • Create and add Label display of volume setting
  14. • Create and add Label display of balance setting
  15.  
  16. */
  17.  
  18. public class Lab7Part3 extends JFrame implements ChangeListener {
  19.  
  20. private JLabel labelVolume = new JLabel("Current Volume: ");
  21. private JLabel labelBalance = new JLabel("Current Balance:");
  22. //JSlider
  23. private JSlider sliderVolume = new JSlider();
  24. private JSlider sliderBalance = new JSlider();
  25.  
  26. private Lab7Part3(){
  27.  
  28. JPanel thePanel = new JPanel ();
  29. JPanel thePanel1 = new JPanel ();
  30. JPanel thePanel2 = new JPanel ();
  31.  
  32. //max and min value
  33. sliderVolume.setMaximum (30);
  34. sliderVolume.setMinimum (0);
  35. sliderBalance.setMaximum (5);
  36. sliderBalance.setMinimum (-5);
  37.  
  38. sliderBalance.setValue (0);
  39. sliderVolume.setValue (0);
  40.  
  41.  
  42. sliderVolume.addChangeListener (this);
  43. sliderBalance.addChangeListener (this);
  44.  
  45. thePanel1.add(sliderBalance);
  46. thePanel1.add (labelBalance);
  47.  
  48.  
  49. thePanel2.add(sliderVolume);
  50. thePanel2.add (labelVolume);
  51.  
  52. thePanel.add (thePanel1,BorderLayout.NORTH);
  53. thePanel.add (thePanel2,BorderLayout.CENTER);
  54.  
  55. getContentPane ().add (thePanel);
  56. setSize(500,200);
  57. setVisible(true);
  58. }
  59. public static void main(String[] args) {
  60. new Lab7Part3 ();
  61.  
  62. }
  63.  
  64. @Override
  65. public void stateChanged(ChangeEvent e) {
  66. labelVolume.setText("Current Volume: " + sliderVolume.getValue());
  67. labelBalance.setText ("Current Balance: " +sliderBalance.getValue ());
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement