1.
Swing class which is used for frames, is
Correct Answer
C. JFrame
Explanation
The correct answer is JFrame. The Swing class is used for creating graphical user interface (GUI) components in Java. JFrame is a class that extends the Window class and provides functionalities for creating and managing frames, which are the main containers for GUI components in a Java application. Therefore, the correct answer is JFrame.
2.
What sets the frame to 300 pixels wide by 200 high?
Correct Answer
D. Frm.setSize( 300, 200 );
Explanation
The correct answer is frm.setSize(300, 200). This method sets the size of the frame to be 300 pixels wide and 200 pixels high.
3.
In what is the size of a frame on the screen measured?
Correct Answer
D. Pixels
Explanation
The size of a frame on the screen is measured in pixels. Pixels are the smallest unit of measurement on a screen and refer to the individual dots that make up an image. The more pixels there are in a frame, the higher the resolution and clarity of the image.
4.
A container object in GUI programming is
Correct Answer
D. An object like a frame that has other GUI components placed inside of it.
Explanation
The correct answer is "An object like a frame that has other GUI components placed inside of it." In GUI programming, a container object refers to an object that can hold and organize other GUI components such as buttons, labels, or text fields. It acts as a parent or holder for these components, allowing them to be arranged and displayed within the container's boundaries. Common examples of container objects in GUI programming include frames, panels, and windows. These containers provide a structure and layout for the GUI components, enabling the creation of complex and interactive user interfaces.
5.
Fill in the blanks to make this program display a JFrame:
import java.awt.*;
public class microGUI
{
public static void main ( String args[] )
{
JFrame frm = new ___________();
frm.___________( 150, 100 );
frm.___________( true );
}
}
Correct Answer
B. JFrame, setSize, setVisible
Explanation
The correct answer is JFrame, setSize, setVisible. In order to display a JFrame, we need to create a new JFrame object using the JFrame class. The setSize method is used to set the size of the JFrame, and the setVisible method is used to make the JFrame visible on the screen. Therefore, the correct code to display a JFrame would be "JFrame frm = new JFrame(); frm.setSize(150, 100); frm.setVisible(true);"
6.
JFrame myFrame = new JFrame ();
Any command (such as the listed one) which creates a new object of a specific class is usually called a...
Correct Answer
A. Constructor
Explanation
The given command "JFrame myFrame = new JFrame();" is creating a new object of the JFrame class. This is done by calling the constructor of the JFrame class, which is a special method used to initialize objects. Therefore, the correct answer is "constructor".
7.
When you create a JFrame object, it is not automatically displayed.
Correct Answer
A. True
Explanation
When a JFrame object is created, it is not automatically displayed because the display of the JFrame is controlled by the programmer. The programmer can choose when and how to display the JFrame by using methods such as setVisible(true) to make it visible on the screen. Therefore, the statement "When you create a JFrame object, it is not automatically displayed" is true.
8.
How do you import all the classes in the AWT and Swing packages?
Correct Answer
D. Import java.awt.*
import javax.swing.*
Explanation
This answer is correct because it imports all the classes in the AWT and Swing packages by using the wildcard (*) after the package names. This means that all the classes within these packages will be accessible in the current code file.
9.
In Java, what do you name an area on the screen that has fine borders and various buttons on the top border?
Correct Answer
D. A frame.
Explanation
In Java, an area on the screen that has fine borders and various buttons on the top border is called a frame. A frame is a container that holds other components such as buttons, text fields, or labels. It provides a window-like structure with a title bar, minimize, maximize, and close buttons. Frames are commonly used to create graphical user interfaces (GUIs) in Java applications.
10.
Upon clicking the X (close) button on a window, it looks like you have "killed" the program when in reality, it keeps on running, but you see no frame. This happened because you forgot to use the setDefaultCloseOperation( ) method, so by default, it used...
Correct Answer
B. JFrame.HIDE_ON_CLOSE
Explanation
When the X (close) button on a window is clicked without using the setDefaultCloseOperation( ) method, the default close operation is used. In this case, the default close operation is JFrame.HIDE_ON_CLOSE. This means that when the X button is clicked, the window is hidden, but the program continues to run in the background. So, although it may appear that the program has been "killed" because the window is no longer visible, it is actually still running.