1.
What three types of software are needed in a complete GUI program?
Correct Answer
A. GUI Components, Event Methods, Application Methods
Explanation
In a complete GUI program, GUI components are needed to create the visual elements of the user interface, such as buttons, labels, and text fields. Event methods are necessary to handle user interactions with these components, such as button clicks or text input. Application methods are required to perform the desired actions or operations based on these user interactions. These three types of software work together to create a functional and interactive graphical user interface.
2.
How is a GUI component (such as a button) placed into a JFrame?
Correct Answer
B. Add( Component c )
Explanation
To place a GUI component, such as a button, into a JFrame, the correct method to use is "add(Component c)". This method is used to add the specified component to the container. In this case, the JFrame acts as the container and the button is the component being added. By using the "add" method, the button will be properly placed and displayed within the JFrame.
3.
What is the Java software that determines how the components of a container are displayed?
Correct Answer
D. Layout Manager
Explanation
The Java software that determines how the components of a container are displayed is called the Layout Manager. It is responsible for arranging and positioning the components within a container, based on various layout rules and constraints. The Layout Manager helps in achieving a consistent and organized visual representation of the components, ensuring proper alignment and spacing.
4.
Which manager displays components row-by-row, in the order in which they were added to the Frame?
Correct Answer
B. FlowLayout
Explanation
FlowLayout is the correct answer because it arranges components in a row-by-row manner, placing them in the order in which they were added to the frame. This layout manager is commonly used for creating simple and straightforward user interfaces where components are arranged horizontally until there is no more space, at which point they wrap to the next row.
5.
What method of a JFrame is used to choose the layout manager?
Correct Answer
A. SetLayout()
Explanation
The setLayout() method of a JFrame is used to choose the layout manager. This method allows the programmer to specify the layout manager that will be used to arrange the components within the JFrame. By calling setLayout() and passing in the desired layout manager as an argument, the programmer can control how the components are positioned and sized within the JFrame.
6.
What interface must a class implement in order to be a listener for button ActionEvents?
Correct Answer
C. ActionListener
Explanation
A class must implement the ActionListener interface in order to be a listener for button ActionEvents. This interface provides the necessary methods to handle action events, such as actionPerformed(), which is invoked when a button is clicked. By implementing ActionListener, the class can receive and respond to button actions.
7.
What method must be implemented in a listener for button events?
Correct Answer
D. ActionPerformed()
Explanation
The actionPerformed() method must be implemented in a listener for button events. This method is called when a button is clicked and it allows the listener to perform the desired action or behavior in response to the button event.
8.
What method of a content pane changes its color?
Correct Answer
A. SetBackground( Color c )
Explanation
The setBackground( Color c ) method of a content pane changes its color. This method takes a Color object as a parameter and sets the background color of the content pane to the specified color.
9.
When should your program call repaint()?
Correct Answer
C. Whenever a change has been made that should result in a new picture.
Explanation
The program should call repaint() whenever a change has been made that should result in a new picture. This is because repaint() is responsible for requesting the system to repaint the component, which will update the visual representation of the program based on any changes made. Calling repaint() after a change ensures that the updated picture is displayed to the user.
10.
What method will immediately stop a program?
Correct Answer
B. System.exit( 0 )
Explanation
The method System.exit(0) will immediately stop a program. This method is used to terminate the currently running Java Virtual Machine (JVM). The argument 0 indicates a successful termination, while a non-zero argument indicates an abnormal termination. When System.exit(0) is called, the program will stop immediately and the control will be returned to the operating system.