Module 03 - GUI
AWT components are heavyweight components that display differently on different platforms. ( AWT ) Swing components are lightweight components that allow a uniform look and feel across different platforms. ( Swing )
( AWT ) ( Swing )
( Container - JComponent - Component ) 1. A component that can contain other components 2. An object that can be displayed on the screen and that can interact with the user 3. Superclass of all lightweight Swing components
1. Container 2. Component 3. JComponent
Match the description on the left to a LayoutManager on the right. ( BorderLayout - GridLayout - FlowLayout ) 1. This LayoutManager layous out components in the form of a table where indificnal components are placed in specific cells. 2. This LayoutManager lays out components row by row. If the window gets resized and the components no longer fit in a row, the components get moved to the next row and the next etc.
1. GridLayout 2. FlowLayout
Which of the following best describes how to respond to an event? A) - Create an event handler class - Implement the appropriate event-listener interface - Register the event handler object B) - Create an inner class - Make sure it extends the class ActionListener - Register the event handler interface C) - Create an interface for event handling - Call it event-listener interface - Implement the interface in an inner class
A)
Layout managers provide the following functionality: A. They calculate the sizes for a container and they lay out the container's childeren B. They calculate the sizes for a container and they line up the children side by side. C. They determine the background colors for a container and they lay out the container's childeren
A. They calculate the sizes for a container and they lay out the container's childeren
Which of the following best describes the order in which components are displayed in a GridLayout? A. Whether components are displayed row by row or column by column can be set by the container. B. The components are always displayed column by column C. The components are always displayed row by row
A. Whether components are displayed row by row or column by column can be set by the container.
Many programs call the method setDefaultCloseOperation from JFrame and pass a static constant to ensure that the application is terminated when the user presses the x button on the top right of the window. What constant is passed to achieve that functionality? A. CLOSE_AND_EXIT B. EXIT_ON_CLOSE C. HIDE_ON_CLOSE D. DISPOSE_AND_EXIT
B. EXIT_ON_CLOSE
Complete the sentence: Labels can display _______________ . A. neither text nor an image B. text and / or an image C. only text D. only an image
B. text and / or an image
You need to write some code that responds to a text change in a JTextField. How can you do that? A. Create a class that implements the interface ActionListener and override the method textFieldChanged B. Create a class that extends the superclass ActionListener and override the method textFieldChanged C. Create a class that implements the interface ActionListener and override the method actionPerformed D. Create a class that extends the superclass ActionListener and override the method actionPerformed
C. Create a class that implements the interface ActionListener and override the method actionPerformed
Java provides an interface that includes constants that are used in combination with Swing GUI. What is the name of this interface? A. SwingValues B. SwingInfo C. SwingConstants D. SwingConstant
C. SwingConstants
Which of the options below best completes the following sentence? In connection with dialogs, the word modal means ...................... . A. having multiple modes. B. displaying different behaviors for option A and option B C. blocking user input to all other windows when visible D. blocking user input to the parent window.
C. blocking user input to all other windows when visible
Let's assume someone created a grid using a GridLayout where the number of rows is set to 3 and the number of columns is set to 4. Let's further assume that we add 5 elements to the grid. Which of the following best describes the resulting grid? A. A grid with 3 rows and 4 columns where the first column and the beginning of the column are filled but the third and fourth columns are empty. B. A grid with 2 rows and 4 columns ( the number of rows gets ignored) C. A grid with 3 rows and 4 columns where the first row and the beginning of the second row are filled but the third row is empty. D. A grid with 3 rows and 2 columns (the number of columns gets ignored)
D. A grid with 3 rows and 2 columns (the number of columns gets ignored)
Which of the following options best describes GridLayout? A. The container is divided into equal-sized rectangles, but rows can be merged so that some components can take up more horizontal space than others. B. The container is divided into equal-sized rectangles, but columns can be merged so that some components can take up more vertical space than others. C. The container is divided into rectangles, but they can vary in sizes because both rows and columns can be merged to create larger cells. D. The container is divided into equal-sized rectangles, and one component is placed in each rectangle.
D. The container is divided into equal-sized rectangles, and one component is placed in each rectangle.
Which of the following is NOT a method of JFrame? A. setVisible B. setSize C. setDefaultCloseOperation D. setToolTip
D. setToolTip
Icon is a class that implements the interface jIcon. True or False?
False
Which class provides the basic attributes and behavior of a window - a title bar and buttons to minimize, maximize and close the window? ____________
JFrame
An inner-class object can directly access all the variables and methods of the outer class. True or False?
True
Event are special things that are happening e.g. a user clicking a button or a user moving a mouse. True or False?
True
JComponents must be placed insdie a top-level container e.g. JFrame, JDialog, or JApplet. True or False?
True
Which of the following classes is used in Swing to create dialogs? a. JOptionPane b. JDialogPane c. JOptionDialog d. JDialogOption
a. JOptionPane
Graphical User Interfaces should be user-friendly. Identify three (3) characteristics we should strive for in order to make GUIs user-friendly. a. animated b. colorful c. consistent d. easy to navigate e. include a menu f. intuitive
c. consistent d. easy to navigate f. intuitive