analyze the following code : import java.awt.*; import java.awt.event.*; import
ID: 3848646 • Letter: A
Question
analyze the following code :
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame implements ActionListener {
public void Test() {
JButton jbtOK = new JButton("OK");
getContentPane().add(jbtOK);
}
public void actionPerformed(ActionEvent e) {
System.out.println("The OK button is clicked");
}
public static void main(String[] args) {
JFrame frame = new Test();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
what is the answer
A) The message "The OK button is clicked" is displayed when you click the OK button.
B) The program has a syntax error because no listeners are registered with jbtOK.
C) The program has a runtime error because no listeners are registered with jbtOK.
D) The actionPerformed method is not executed when you click the OK button, because no instance of Test is registered with jbtOK.
E) None of the above.
Explanation / Answer
Answer: D the actionPerformed methods is not executed when you click OK button, because no instance of Test is registered with jbtOK.
A) when ok button is pressed no output will be shown.
B) there is syntax error, in the program because there is no instance of Test is registered.
C) there will be no runtime error, because the program executes but actionPerformed part will not be executed from the output.
E) the Test instance is not registered with jbtOK, so none of the above answer is wrong.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.