Study the following code import javaawt import javaawtevent
Study the following code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends A {
public static void main(String[] args) {
A frame = new Test();
frame.setSize(200, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class A extends JFrame implements ActionListener {
JButton jbtCancel = new JButton(\"Cancel\");
JButton jbtok = new JButton(\"OK\");
public A() {
getContentPane().setLayout(new FlowLayout());
getContentPane().add(jbtCancel);
jbtCancel.addActionListener(this);
getContentPane().add(jbtok);
jbtok.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jbtCancel) {
System.out.println(\"Cancel button is clicked\");
}
if (e.getSource() == jbtok) {
System.out.println(\"OK button is clicked\");
}
}
}
Select one:
a. The program displays Cancel button on the left of the OK button.
b. When you click the OK button the message \"OK button is clicked\" is displayed.
c. When you click the Cancel button the message \"Cancel button is clicked\" is displayed.
d. All of the above
Solution
The program displays Cancel button on the left of the OK button.
Yes because Cancel button was added before OK button.
When you click the OK button the message \"OK button is clicked\" is displayed.
Yes OK button is clicked message is displayed in the console.
When you click the Cancel button the message \"Cancel button is clicked\" is displayed.
Yes Cancel button is clicked message is displayed in the console.
Hence the answer is all of the above.
![Study the following code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Test extends A { public static void main(String[] args) Study the following code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Test extends A { public static void main(String[] args)](/WebImages/23/study-the-following-code-import-javaawt-import-javaawtevent-1056076-1761550987-0.webp)