Question
Given the program below, how many frames are displayed? import javax.swing.*; public class Test { public static void main(String[] args) { JFrame f1 = new
- Given the program below, how many frames are displayed?
import javax.swing.*;
public class Test {
public static void main(String[] args) {
JFrame f1 = new JFrame("My Frame");
JFrame f2 = f1;
JFrame f3 = f2;
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
}
}
A. 0
B. 1
C. 2
D. 3
E. Program will not compile. Need additional import
- Given the program below, how many frames are displayed?
import javax.swing.*;
public class Test extends JFrame {
public static void main(String[] args) {
JFrame f1 = new Test();
JFrame f2 = new Test();
JFrame f3 = new Test();
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
}
}
A. 0
B. 1
C. 2
D. 3
- Given the SimpleWindow program in Fig 17.4 (p765) and the fact that class SimpleWindow has only two methods (constructor and createContents), ________.
A. Those setXX methods used in the constructor must come from the super class JFrame.
B. the main() can call either the constructor (using new operator) or call the createContents method of a SimpleWindow object
C. if the main() contains a line of System.out.println(s) and s is a SimpleWindow object, then a message "Simple Window" will be printed
D. All of the above
- Given the Greeting program in Fig 17.5 (p772-773), what will happen if you remove the "private JLabel greeting;" line and then add such a label to createContents() as local variable ("JLabel greeting;")?
A. the program will not compile.
B. the program will compile fine but will throw run time exception.
C. the program will compile and work the same as before.
D. None of the above
- If you compile the Greeting.java in Fig 17.5 (p772-773), you will end up with three .class files:
Greeting$1.class
Greeting$Listener.class
Greeting.class
Do some research and report what those first two class files are (with $ in the name).
- Analyze the following code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
public void Test() {
JButton jbtOK = new JButton("OK");
add(jbtOK);
jbtOK.addActionListener(new ActionListener() {
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);
}
}
A. The program has a compile error because no listeners are registered with jbtOK.
B. The program has a runtime error because no listeners are registered with jbtOK.
C. The message "The OK button is clicked" is displayed when you click the OK button.
D. The actionPerformed method is not executed when you click the OK button, because no instance of Test is registered with jbtOK.
E. When you run the program, the button is not displayed
- In the FactorialButton program in Fig 18 (p781-782), the xfBox.setText("undefined"); statement (true branch of the if (x<0) block) will be executed when _________.
A. user enters a zero
B. user enters a negative integer
C. a non-integer string is provided by user
D. More than one statement of the first three statements are correct
E. All first three statements are correct.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started