Which statement is true with respect to the following code i

Which statement is true with respect to the following code?


import java.awt.*;
import javax.swing.*;

public class Test {
   public static void main(String[] args) {
      JFrame frame = new JFrame(\"My Frame\");
      frame.getContentPane().add(new JButton(\"OK\"));
      frame.getContentPane().add(new JButton(\"Cancel\"));
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(200, 200);
      frame.setVisible(true);
   }
}

Select one:

a. Only button OK is displayed.

b. Only button Cancel is displayed.

c. Both button OK and button Cancel are displayed and button OK is displayed on the left side of button Cancel.

d. Both button OK and button Cancel are displayed and button OK is displayed on the right side of button Cancel.

Solution

Ans: b. Only button Cancel is displayed.

frame.getContentPane().add(new JButton(\"OK\"));
This line add OK biutton in entire frame

frame.getContentPane().add(new JButton(\"Cancel\"));
This line override already OK button and add Cancel button on entire frame

Which statement is true with respect to the following code? import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site