Create a graphical user interface program named MoodButtonDemo that will be run
ID: 3633551 • Letter: C
Question
Create a graphical user interface program named MoodButtonDemo that will be run as a regular Java application (meaning it contains a main method). Inside the main method, you will have two statements. The first statement will declare and instantiate an object of the MoodButton class. The second statement will make the GUI visible.
The MoodButton class will be derived from the class JFrame. The GUI should initially have a white background with three mood buttons visible (“Happy”, “Mad” and “Sad”) centered across the top of the GUI. When one button is clicked, that button disappears and only the other buttons are visible. Thereafter, only two buttons are visible at a time; when the button is clicked, it disappears and the other buttons appear. When the “Happy” button is clicked, the background color changes to yellow and happy, smiling face is displayed. When the “Mad” button is clicked, the background color changes to red and mad, angry face is displayed. When the “Sad” button is clicked, the background color changes to grey and sad, frowning face is displayed. When the program is first run, no face is visible on the white background in the GUI. Subsequent faces should replace the previous faces.
After five button clicks, the message “Only one more click” appears under the buttons. After one more click, the program ends.
The program should be done complete in the way i have asked in order for me to get ALL the points. The code should also have comments(//) explaining what each code does. Follow each steps clearfully and don't leave out no details. THANKS!!!
Explanation / Answer
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.ImageIcon; import java.awt.Graphics; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class MoodButton extends JFrame implements ActionListener { public static final int ZERO = 0; public static final int FIVE_HUNDRED = 500; public static final int FIVE = 5; public static final int SIX = 6; private String actionCommand; private int numberOfButtonPushes = ZERO; private boolean isHappy = false; private boolean isSad = false; private boolean isMad = false; private boolean isButtonClicked = false; private JButton happy = new JButton("Happy"); private JButton mad = new JButton("Mad"); private JButton sad = new JButton("Sad"); private ImageIcon happyIcon = new ImageIcon("happy.png"); private ImageIcon madIcon = new ImageIcon("mad.png"); private ImageIcon sadIcon = new ImageIcon("sad.png"); private JLabel smiley = new JLabel(); private Container contentPane = getContentPane(); private WindowDestroyer listener = new WindowDestroyer(); public MoodButton() { this.setSize(FIVE_HUNDRED, FIVE_HUNDRED); this.setTitle("Project 13"); this.addWindowListener(listener); contentPane.setLayout(new FlowLayout()); happy.addActionListener(this); contentPane.add(happy); mad.addActionListener(this); contentPane.add(mad); sad.addActionListener(this); contentPane.add(sad); } public void actionPerformed(ActionEvent e) { isButtonClicked = true; numberOfButtonPushes++; if(numberOfButtonPushesRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.