CH 14: Intro to Swing Components
What is the default layout manager for JFrame?
BorderLayout
When you create a(n) ____, you can group several components, such as JCheckBoxes, so a user can select only one at a time.
ButtonGroup
An object that is interested in an event is called a source.
False
When a JFrame is closed, you can end a program that you have forgotten to exit by typing Alt+E.
False
When a user closes a JFrame by clicking the Close button in the upper-right corner, the default behavior is for the JFrame to close and the application to terminate.
False
You cannot change the font of strings displayed in GUI components.
False
The ____ responds to keyboard focus events.
FocusListener
What class is the immediate parent of JFrame?
Frame
A ____ is a Component used to trigger an action or make a selection when the user clicks it.
JButton
A ____ consists of a label positioned beside a square; you can click the square to display or remove a check mark.
JCheckBox
A ____ is a component that combines a button or an editable field and a drop-down list.
JComboBox
Which statements create a JLabel that holds the words "Happy birthday" and adds the greeting to a JFrame object named aGreeting?
JLabel mygreeting = new JLabel("Happy Birthday"); aGreeting.add(mygreeting);
What is the immediate parent class of JTextField?
JTextComponent
The Swing classes are part of a more general set of UI programming capabilities that are collectively called the ____.
Java Foundation Classes
The ____ responds to keyboard events.
KeyListener
Each Swing component is a descendant of a JComponent.
True
If a user enters more characters than specified in a JTextField, the extra characters are deleted.
True
Java provides you with a Font class from which you can create an object that holds typeface and size information.
True
The default behavior of a JFrame is to use the border layout format, which divides a container into regions.
True
When setting a JFrame's size, part of the area is unusable because it is consumed by the JFrame's title bar and borders.
True
You can use the setEnabled() method to make a component available or unavailable by passing true or false to it.
True
You can call a JFrame's setDefaultCloseOperation() method and use ____ as an argument to keep the JFrame visible and continue running the program.
WindowConstants.DO_NOTHING_ON_CLOSE
The ActionListener interface contains the ____ method specification.
actionPerformed(ActionEvent e)
The JButton, JCheckBox, JComboBox, and JRadioButton components are associated with the ____ method
addItemListener()
The ____ layout manager places components in a row, and when a row is filled, it automatically spills components into the next row.
flow
Look and feel comprises the elements of design, style, and ____ in any user interface.
functionality
Within an implementation of the itemStateChanged() method, you can use the ____ method to determine which object generated the event, and the getStateChange() method to determine whether the event was a selection or a deselection.
getItem()
The ____ method of JComboBox returns the maximum number of items the combo box can display without a scroll bar.
getMaximumRowCount()
A method that executes because it is called automatically when an appropriate event occurs is an event ____.
handler
Which of the following statements will change the value displayed in a JLabel named hello?
hello.setText("Hello");
Which of the following statements will correctly set a JFrame named myFrame to be visible?
myFrame.setVisible(true)
Which constructor constructs a new JTextField with the specified text and columns?
public JTextField(String text, int columns)
Which method overrides the default behavior for the JFrame to be positioned in the upper-left corner of the computer screen's desktop?
setBounds()
A component can be made available or unavailable by passing true or false to the ____ method.
setEnabled()
Which method do you use to assign a font object to a JLabel?
setFont()
Which method sets the state of the JCheckBox to true for selected or false for unselected?
setSelected
Within an event-driven program, a component on which an event is generated is the ____ of the event.
source
Swing components are UI elements such as dialog boxes and buttons. You can usually recognize their names because they begin with ____.
the letter J
Which method do you use to change the state of a JCheckBox?
void setSelected(boolean)
When constructing a Font object, which of the following arguments is NOT required?
weight