Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Which statement is true with respect to the following code? import java.awt.*; i

ID: 3929166 • Letter: W

Question

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.

Explanation / Answer

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