Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a universal remote control for an entertainment system (cable / TV, etc).

ID: 3577036 • Letter: D

Question

Design a universal remote control for an entertainment system (cable / TV, etc). Create the interface as a NetBeans project. Or implement the design of the telephone interface for a smartphone. In this assignment you need to have event listeners associated with the components on the GUI. This assignment is about creating a few event handlers to acknowledge activity on you interface. Acknowledgment of activity can be as simple as displaying a text message when an event occurs with a component on your interface such as; a button is pressed, a check box or radio button is clicked, a slider is moved or a combo box item is selected.

Explanation / Answer

import java.awt.*;

import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class RemoteControl extends JPanel
{

//intializing button and sliders
   private JButton channelUpButton;
   private JButton channelDownButton;
   private JButton oneButton;
   private JButton fourButton;
   private JButton sevenButton;
   private JButton twoButton;
   private JButton fiveButton;
   private JButton eightButton;
   private JButton threeButton;
   private JButton sixButton;
   private JButton nineButton;
   private JButton zerobutton;
   private JSlider volSlider;
   private JLabel volLabel;

   public RemoteControl()
   {
       //construct components
       channelUpButton = new JButton ("+ Chan");
       channelUpButton.addActionListener(new ChannelListener()); //adding listeners
       channelDownButton = new JButton ("- Chan");
       channelDownButton.addActionListener(new ChannelListener());
       JButton ("1");
       oneButton.addActionListener(new ChannelChangeListener());
       fourButton = new JButton ("4");
       fourButton.addActionListener(new ChannelChangeListener());
       sevenButton = new JButton ("7");
       sevenButton.addActionListener(new ChannelChangeListener());
       twoButton = new JButton ("2");
       twoButton.addActionListener(new ChannelChangeListener());
       fiveButton = new JButton ("5");
       fiveButton.addActionListener(new ChannelChangeListener());
       eightButton = new JButton ("8");
       eightButton.addActionListener(new ChannelChangeListener());
       threeButton = new JButton ("3");
       threeButton.addActionListener(new ChannelChangeListener());
       sixButton = new JButton ("6");
       sixButton.addActionListener(new ChannelChangeListener());
       nineButton = new JButton ("9");
       nineButton.addActionListener(new ChannelChangeListener());
       zerobutton = new JButton ("0");
       zerobutton.addActionListener(new ChannelChangeListener());
       volSlider = new JSlider (0, 20);
       volSlider.addChangeListener((new EventHandlerForSlider()));
       volLabel = new JLabel ("Volume");

       //set components properties
       volSlider.setOrientation (JSlider.HORIZONTAL);
       volSlider.setMinorTickSpacing (1);
       volSlider.setMajorTickSpacing (5);
       volSlider.setPaintTicks (true);
       volSlider.setPaintLabels (true);

       //adjust size and set layout
       setPreferredSize (new Dimension (189, 343));
       FlowLayout layout = new FlowLayout();
       setLayout (layout);

       //add components
       add (channelUpButton);
       add (channelDownButton);
       add (volLabel);
       add (volSlider);
       add (oneButton);
       add (twoButton);
       add (threeButton);
       add (fourButton);
       add (fiveButton);
       add (sixButton);
       add (sevenButton);
       add (eightButton);
       add (nineButton);
       add (zerobutton);

       //set component bounds
       channelUpButton.setBounds (0, 136, 90, 40);
       channelDownButton.setBounds (98, 136, 90, 40);
       oneButton.setBounds (10, 215, 50, 25);
       fourButton.setBounds (10, 245, 50, 25);
       sevenButton.setBounds (10, 275, 50, 25);
       twoButton.setBounds (70, 215, 50, 25);
       fiveButton.setBounds (70, 245, 50, 25);
       eightButton.setBounds (70, 275, 50, 25);
       threeButton.setBounds (130, 215, 50, 25);
       sixButton.setBounds (130, 245, 50, 25);
       nineButton.setBounds (130, 275, 50, 25);
       zerobutton.setBounds (70, 305, 50, 25);
       volSlider.setBounds (0, 60, 187, 50);
       volLabel.setBounds (4, 22, 100, 25);
   }

   public class ChannelListener implements ActionListener {
       // Set actionlistener
       public void actionPerformed(ActionEvent e) {
           System.out.println("The user is changing the channel "+((JButton) e.getSource()).getText());//printing the button which is clicked
       }
   }
  
   public class ChannelChangeListener implements ActionListener {
       // Set actionlistener
       public void actionPerformed(ActionEvent e) {
           System.out.println("Channel "+((JButton) e.getSource()).getText()+" has been selected");//printing the button which is clicked
       }
   }
  

//slider event change listener
   public class EventHandlerForSlider implements ChangeListener {
      
       @Override
       public void stateChanged(ChangeEvent e) {
           System.out.println("Volume level is "+((JSlider) e.getSource()).getValue());//printing the button which is clicked
          
       }
   }

   public static void main (String[] args)
   {
       JFrame frame = new JFrame ("JPanel Preview");// Jframe object
       frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
       frame.getContentPane().add (new RemoteControl());
       frame.pack();
       frame.setVisible (true);
   }
}

-------------------------------------------------------------output--------------------------------------------------------------------------

Channel 0 has been selected
Channel 7 has been selected
The user is changing the channel + Chan
The user is changing the channel - Chan
Volume level is 10
Volume level is 9
Volume level is 8
Volume level is 7
Volume level is 8
Volume level is 9
Volume level is 9

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote