Which of the following statements registers a panel object aPanel as a listener
ID: 643686 • Letter: W
Question
Which of the following statements registers a panel object aPanel as a listener for a button variable aButton?
Question 15 options:
addActionListener(aPanel);
aButton.addActionEventListener(aPanel);
aPanel.addEventListener(aPanel);
aButton.addActionListener(aPanel);
Save
Question 16 (5 points)
In the program below, which object is listening for the events of okButton?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Quiz3B extends JFrame implements ActionListener
{
private JButton okButton = new JButton("OK");
public Quiz3B()
{
add(okButton);
okButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
System.out.println("The OK button is clicked");
}
public static void main(String[] args)
{
JFrame frame = new Quiz3B();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Question 16 options:
JButton
An anonymous object
okButton
frame
Save
Question 17 (5 points)
What is the benefit of using adapter classes rather than listeners interfaces?
Question 17 options:
It enables multiple inheritance of classes
It makes it possible to respond to several events at the same time
It makes it unnecessary to implement unused event handling methods
It makes the response time for responding to events much quicker
Save
Question 18 (5 points)
In the program below, which object is listening for the events of okButton?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Quiz3C extends JFrame
{
private JButton okButton = new JButton("OK");
public Quiz3C()
{
add(okButton);
okButton.addActionListener(
new ActionListener()
{
@Override
public void actionPerformed(ActionEvent ae)
{
System.out.println("The OK button is clicked");
}
});
}
public static void main(String[] args)
{
JFrame frame = new Quiz3C();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Question 18 options:
An anonymous object
okButton
JButton
frame
Save
Question 19 (5 points)
Which of the following will occur if you fail to register an object as a listener for the click events of a button?
Question 19 options:
A compilation error will occur
A class cast exception will be thrown at run-time
The containing frame will be considered as the default listener
Nothing will happen when the button is clicked
Save
Question 20 (5 points)
When a mouse event is generated how is the location of the click point determined?
Question 20 options:
The event handler must generate a secondary event to obtain the location
It is extracted from the mouse event that is passed to the event handler
It is automatically saved as an instance variable in the object of which the mouse was clicked
It is obtained by calling a method of the mouse object
Save
Save All Responses
addActionListener(aPanel);
aButton.addActionEventListener(aPanel);
aPanel.addEventListener(aPanel);
aButton.addActionListener(aPanel);
Which of the following statements registers a panel object aPanel as a listener for a button variable aButton? Question 15 options: In the program below, which object is listening for the events of okButton? What is the benefit of using adapter classes rather than listeners interfaces? In the program below, which object is listening for the events of okButton? Which of the following will occur if you fail to register an object as a listener for the click events of a button? When a mouse event is generated how is the location of the click point determined?Explanation / Answer
15)
The syntax for registering a component to an action listener class:
component.addActionListener(object Of a listener);
Hence the correct option is “D) aButton.addActionListener(aPanel);”.
16)
component.addActionListener(object Of a listener);
Hence the correct option is “D) frame”.
17)
Hence the correct option is “C. It makes it unnecessary to implement unused event handling methods”.
18)
Hence the correct option is “A) An anonymous object”.
19)
Hence the correct option is “D) Nothing will happen when the button is clicked”.
20)
Hence the correct option is “B) It is extracted from the mouse event that is passed to the event handler”
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.