3 6 9 € 10 11 1 import javax.swing.*; 2 import java.awt.event.*; 4 public class SimpleEvent extends JFrame 5 implements
Posted: Sun May 15, 2022 2:07 pm
3 6 9 € 10 11 1 import javax.swing.*; 2 import java.awt.event.*; 4 public class SimpleEvent extends JFrame 5 implements ActionListener { JPanel p = new JPanel(); JButton b = new JButton("click Me"); 8 JCheckBox cb = new JCheckBox ("Check Me"); SimpleEvent (String text) { super (text); p.add(cb); 12 p.add (b); 13 add (p); 14 cb.addActionListener(this); 15 setSize (300,100); 16 setVisible(true); 17 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ; public void actionPerformed (ActionEvent e) { System.out.println("Hello"); 21 } 22 public static void main(String[] args) { 23 new SimpleEvent("test"); 24 } 25 ) 18 19 20 NNNNNN co OM 5.1 At which line the frame title is set? How is it set? (1 point) 5.2 Describe what happens when a user click the button after executing the program. Explain your reasoning. (2 points) 5.3 Modify the source code so that the object of SimpleEvent is not a listener, and a listener is an object of an inner class of SimpleEvent. Note that the result of the program must be the same. (2 points) 5.4 Explain what you should do if you want the program to print the word "Hello" only when the source of the ActionEvent object is the button. Also, modify the source code so that the program prints the word “Hello" only when a user click the button. If a user checks the checkbox, it prints your student ID. (2 points)