Question: In the program below, which Java statement registers an event listener object with an event source? ClassB b = new ClassB(); myFrame.getContentPane().add( button1 ); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

In the program below, which Java statement registers an event listener object with an event source?

In the program below, which Java statement registers an event listener object

ClassB b = new ClassB();
myFrame.getContentPane().add( button1 );
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button1.addActionListener( b );

import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing. JFrame; public class ClasSA public static void main( String [] args ) JFrame myFrame new JFrame ("Something"); myFrame.setLayout new FlowLayout); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) myFrame.setSize( 275, 110); JButton button1new JButton ("Button 1"); ClassB bnew ClassB(); button1.addActionListener( b); myFrame.getContentPane().add( button1); myFrame.setVisible(true); class ClassB implements ActionListener f public void actionPerformed(ActionEvent e) f System.out.println ("Something happened")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!