3 6 9 € 10 11 1 import javax.swing.*; 2 import java.awt.event.*; 4 public class SimpleEvent extends JFrame 5 implements

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

3 6 9 € 10 11 1 import javax.swing.*; 2 import java.awt.event.*; 4 public class SimpleEvent extends JFrame 5 implements

Post by answerhappygod »

3 6 9 10 11 1 Import Javax Swing 2 Import Java Awt Event 4 Public Class Simpleevent Extends Jframe 5 Implements 1
3 6 9 10 11 1 Import Javax Swing 2 Import Java Awt Event 4 Public Class Simpleevent Extends Jframe 5 Implements 1 (158.06 KiB) Viewed 55 times
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)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply