Programming Languages Chapter 12 Which of the following is not a GUI component

subject Type Homework Help
subject Pages 10
subject Words 3184
subject Authors Harvey Deitel, Paul Deitel

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 12: GUI Components: Part 1
12.1 Introduction
12.1 Q1: Which of the following is not a GUI component (control or widget)?
a. String.
b. Button.
c. Menu.
d. Combo box.
12.1 Q2: Which component contains menus?
a. Menu button.
b. Title bar.
c. Menu bar.
d. Combo box.
12.2 Java’s Nimbus Look-and-Feel
12.3 Simple GUI-Based Input/Output with
12.3 Q1: Which of the following is the method used to display a dialog box to gather
input?
a. showMessageDialog.
b. getInput.
c. inputDialog.
d. showInputDialog.
12.3 Q2: The text “Hello there, my friend.” is an example of what type of capitalization?
a. sentence-style capitalization.
b. book-title capitalization.
c. Neither of the above.
d. Both of the above.
page-pf2
12.3 Q3: The JOptionPane constant used to display an icon prompting the user for input
is:
a. JOptionPane.ERROR_MESSAGE.
b. JOptionPane.INFORMATION_MESSAGE.
c. JOptionPane.QUESTION_MESSAGE.
d. JOptionPane.WARNING_MESSAGE.
12.4 Overview of Swing Components
12.4 Q1: Which of the following statements for a JTextField is false?
a. Can be used to display uneditable text.
b. Can be used to display editable text.
c. Enables users to enter data from the keyboard.
d. Displays a list of fields.
12.4 Q2: Together, the appearance and the way in which the user interacts with the
application are known as that application’s ________.
a. abstract window toolkit.
b. look-and-feel.
c. swing factor.
d. All of the above.
12.4 Q3: Which of the following statements about Swing GUI components is false?
a. Swing components are less portable but more flexible than the original Java GUI
components from package java.awt.
b. Most Swing components are written completely in Java.
c. Swing components allow the user to specify a uniform look-and-feel across all
platforms.
d. Swing components allow the user to change the look-and-feel while the program is
running.
12.4 Q4: Which of the following statements about heavyweight components is false?
a. AWT components are not heavyweight components.
b. Several Swing components are heavyweight components.
page-pf3
c. The look-and-feel may vary across platforms.
d. The functionality may vary across platforms.
12.4 Q5: Which pair of words does not complete the sentence below correctly?
A ________ is a(n) ________.
a. Container, Component.
b. Container, JPanel.
c. JComponent, Container.
d. Component, Object.
12.4 Q6: Some common lightweight component features supported by JComponent
include:
a. support for user-interface localization.
b. shortcut keys.
c. tool tips.
d. All of the above.
12.5 Displaying Text and Images in a Window
12.5 Q1: provides the basic attributes and behaviors of a windowa title bar
at the top of the window, and buttons to minimize, maximize and close the window.
a. JLabel.
b. JFrame.
c. JSwing.
d. JWindowControl.
12.5 Q2: Which of the following statements about a JLabel is false?
a. Applications rarely change a label’s contents after creating it.
b. A JLabel can display text and an image.
c. A JLabel can display text and a button.
d. A JLabel is a subclass of JComponent.
12.5 Q3: Method can be used to set the layout manager of a container.
a. setManager
b. setLayout
c. setLayoutManager
d. setGUILayout
page-pf4
12.5 Q4: A JLabel can be attached to a JFrame using method ________.
a. attach
b. contain
c. append
d. add
12.5 Q5: Which method sets the text that's displayed when the user hovers over a
JLabel?
a. setHover
b. setHoverText
c. setToolTip
d. setToolTipText
12.5 Q6: Which of the following expressions creates a JLabel that displays the text
"Here is what I look like!" The JLabel should display Icon object face, and the
JLabel’s contents should be left aligned.
a. new JLabel("Here is what I look like!", face, SwingConstants.LEFT)
b. new JLabel("Here is what I look like!", face, SwingJustification.LEFT)
c. new JLabel("Here is what I look like!", SwingConstants.LEFT, face)
d. new JLabel("Here is what I look like!", SwingJustification.LEFT, face)
12.5 Q7: Which methods retrieve and set the image that's displayed in a JLabel?
a. getIcon, setIcon.
b. getResource, setResource.
c. getText, setText.
d. getImageIcon, setImageIcon.
12.5 Q8: Which JFrame constant indicates that the program should terminate when the
window is closed by the user?
a. TERMINATE_ON_CLOSE.
b. IMMEDIATELY_CLOSE.
c. EXIT_ON_CLOSE.
d. All of the above.
12.6 Text Fields and an Introduction to Event
page-pf5
12.6 Q1: Which of the following does not generate GUI events?
a. Typing in a text field.
b. Selecting an item from a menu.
c. Viewing the text in a label.
d. Moving the mouse.
12.6 Q2: Which of the following is false?
a. A JPasswordField shows that characters are being entered, but hides the actual
character with an echo character.
b. Class JTextField extends JTextComponent; Class JPasswordField extends
JTextField.
c. Both JTextFields and JPasswordFields are single-line areas in which the user can
enter text via the keyboard.
d. JPasswordFields generate events; JTextFields do not.
12.6 Q3: Which of the following statements makes the text in a JTextField uneditable?
a. textField.setEditable(true);
b. textField.setEditable(false);
c. textField.setUneditable(true);
d. textField.setUneditable(false);
12.6 Q4: Which of the following most completely describes the steps for setting up event
handling for a GUI component?
a. Create a class that represents the event handler, attach the JFrame to a JWindow object
and register the event handler.
b. Implement an appropriate event-listener interface and register the event handler.
c. Create a class that represents the event handler and implement an appropriate event-
listener interface.
d. Create a class that represents the event handler, implement an appropriate event-
listener interface and register the event handler.
12.6 Q5: Which of the following answers does not complete the sentence correctly?
An anonymous inner class .
a. is frequently used for GUI event handling
b. is non-static
c. does not need a handle to its outer class to access its methods and variables
d. cannot be declared private
12.6 Q6: When the user presses Enter in a JPasswordField, the GUI component
page-pf6
generates an , which is processed by an object that implements the interface
.
a. ActionEvent, ActionListener.
b. ActionEvent, ActionEventListener.
c. TextEvent, TextListener.
d. TextEvent, TextEventListener.
12.6 Q7: Forgetting to register an event-handler object for a particular GUI component’s
event type causes .
a. events of that type to be ignored.
b. all of the GUI component's events to be ignored.
c. a compilation error.
d. None of the above.
12.6 Q8: JPasswordField contains method to obtain the data entered.
a. getInput.
b. getPassword.
c. getText.
d. getEcho.
12.6 Q9: The GUI event with which the user interacts is the .
a. event effector.
b. event container.
c. event raiser.
d. event source.
12.7 Common GUI Event Types and Listener
12.7 Q1: Which of the following is not necessary to use the event delegation model?
a. An event listener must be registered.
b. An event handler must be implemented.
c. The appropriate interface must be implemented.
d. The appropriate interface must be registered.
12.7 Q2: Which of the following completes the sentence below correctly?
A(n) is a(n) .
a. InputEvent, MouseEvent.
page-pf7
b. ActionEvent, AdjustmentEvent.
c. FocusEvent, WindowEvent.
d. ContainerEvent, ComponentEvent.
12.8 How Event Handling Works
12.8 Q1: Every JComponent has an instance variable called that enables the
object to maintain references to all its registered listeners.
a. registeredListenerList
b. listenerList
c. registeredList
d. eventListenerList
12.8 Q2: How many event-listener interfaces correspond to each event type?
a. one.
b. two.
c. one or more.
d. zero.
12.9 JButton
12.9 Q1: Which of the following choices completes the sentence correctly?
A(n) is a(n) .
a. JToggleButton, JCheckBox
b. JToggleButton, JRadioButton
c. JButton, JToggleButton
d. JButton, AbstractButton
12.9 Q2: The method setRolloverIcon is used to ________.
a. Handle a key event
b. Change the button text
c. Change the button icon
d. All of the above
12.9 Q3:Which of the following is not a type of button?
a. command buttons.
page-pf8
b. toggle buttons.
c. check boxes.
d. All of the above are types of buttons.
12.10 Buttons That Maintain State
12.10 Q1: Which of the following is stateless?
a. JButton.
b. JToggleButton.
c. JRadioButton.
d. JCheckBox.
12.10 Q2: A JRadioButton is different from a JCheckBox in that .
a. a JRadioButton is a subclass of JToggleButton, JCheckBox is not.
b. normally several JRadioButtons are grouped together and are mutually exclusive.
c. a JRadioButton is a type of button, JCheckBox is not.
d. a JRadioButton is a state button, JCheckBox is not.
12.10.1 JCheckBox
12.10.1 Q1: When the user clicks a JCheckBox, a(n) occurs.
a. CheckedEvent
b. ButtonEvent
c. ItemEvent
d. ActionEvent
12.10.1 Q2: Which method determines if a JCheckBox is selected?
a. isSelected
b. getSelected
c. selected
d. None of the above
12.10.2 JRadioButton
page-pf9
12.10.2 Q1: The logical relationship between radio buttons is maintained by objects of
what class?
a. MutualExclusionGroup
b. RadioButtonGroup
c. Group
d. ButtonGroup
12.10.2 Q2: Adding a ButtonGroup object to a container ________.
a. is necessary for the functionality of the ButtonGroup to work properly.
b. causes all the JRadioButtons in the group to have their event handlers registered.
c. results in a compilation error.
d. None of the above.
12.11 JComboBox and Using an Anonymous
12.11 Q1: When the arrow on a JComboBox is clicked:
a. an ItemEvent occurs.
b. a scrollbar always appears.
c. an ActionEvent occurs.
d. The JComboBox expands to a list.
12.11 Q2: The setMaximumRowCount method is used for:
a. Button.
b. JComboBox.
c. JRadioButton.
d. JToggleButton.
12.11 Q3: Which of the following statements about anonymous inner classes is false?
a. They are declared without a name.
b. They typically appear inside a method declaration.
c. They are declared with the anonymous keyword.
d. They can access their top-level class’s members.
12.11 Q4: Method getSelectedIndex of class JComboBox returns:
a. the index of the selected item in the JComboBox.
b. the selected item in the JComboBox, as a String.
c. the index of the previously selected item.
page-pfa
d. None of the above.
12.12 JList
12.12 Q1: A JScrollPane is provided automatically for which of the following?
a. JToggleButton.
b. JRadioButton.
c. JList.
d. None of the above.
12.12 Q2: Selecting a JList item generates ________.
a. an ActionEvent
b. a ListItemEvent
c. a ListSelectionEvent
d. a ListSelectionItemEvent
12.13 Multiple-Selection Lists
12.13 Q1: Consider the list below:
January
February
March
April
May
June
July
August
September
October
November
December
What type of JList selection mode would allow the user to select March, June and July
in one step?
a. SINGLE_SELECTION.
b. SINGLE_INTERVAL_SELECTION.
c. MULTIPLE_INTERVAL_SELECTION.
d. All of the above.
page-pfb
12.13 Q2: Method getSelectedValues of class JList returns:
a. an array of ints representing the indices of the selected items.
b. an array of doubles representing the indices of the selected items.
c. an array of Strings representing the selected items.
d. an array of Objects representing the selected items.
12.14 Mouse Event Handling
12.14 Q1: Which of the following objects cannot trap mouse events?
a. JTextField.
b. ButtonGroup.
c. JButton.
d. JComponent.
12.14 Q2: Which of the following is a MouseMotionListener method?
a. mousePressed.
b. mouseExited.
c. mouseDragged.
d. mouseClicked.
12.14 Q3: The BorderLayout layout manager:
a. divides an area into five regions: NORTH, SOUTH, EAST, WEST and CENTER.
b. divides an area into five regions: UP, DOWN, LEFT, RIGHT and MIDDLE.
c. orders components vertically.
d. order components horizontally.
12.14 Q4: A MouseHandler object implements which two interfaces?
a. MouseListener and MouseActionListener.
b. MouseListener and MouseMotionListener.
c. MouseListener and MouseEventListener.
d. MouseListener only.
12.15 Adapter Classes
12.15 Q1: Which of the following statements about adapters is false?
page-pfc
a. An adapter class implements an interface.
b. An adapter class provides a default (empty) implementation of every method in the
interface.
c. Programmers override selected adapter methods.
d. A ComponentListener is a ComponentAdaptor.
12.15 Q2: In what cases are adapter classes useful?
a. When an adapter GUI control is clicked.
b. When every method in the event-listener interface is to use the same functionality.
c. When it is not desirable to declare every method in the event-listener interface.
d. None of the above.
12.15 Q3: A user of a one-button mouse can simulate pushing the middle button on a
three-button mouse by holding the while clicking the left mouse button.
a. Alt key.
b. Meta key.
c. Ctrl key.
d. Shift key.
12.15 Q4: Which MouseEvent method can be used to determine if the Alt key is pressed?
a. isAltPressed.
b. isAltDown.
c. getClickCount.
d. AltPressed.
12.16 Q1: Method paintComponent is called when:
a. a lightweight Swing component is created.
b. a lightweight Swing component is displayed.
c. a lightweight Swing component is clicked.
d. an application exits.
12.16 Q2: When a component is , paintComponent clears the component’s
background before the component is displayed.
a. transparent
page-pfd
b. opaque
c. oblique
d. concave
12.16 Q3: Class Point represents ________.
a. a filled oval
b. an x-y coordinate pair
c. an object used to draw
d. a period in a sentence
12.16 Q4: Method indicates that a Component should be refreshed on screen
as soon as possible with a call to that control’s paintComponent method.
a. refresh
b. repaint
c. repaintComponent
d. redraw
12.17 Key-Event Handling
12.17 Q1: Which of the following is not a KeyListener method?
a. keyPressed.
b. keyReleased.
c. keyClicked.
d. keyTyped.
12.17 Q2: The Shift key is a(n) key.
a. modifier
b. action
c. output
d. None of the above
12.18 Introduction to Layout Managers
12.18 Q1: Using layout managers ________.
a. provides the greatest level of control over a GUI’s appearance
b. can be faster than creating a GUI with absolute positioning
c. allows the programmer to specify the exact location of each GUI component with
respect to the upper-left corner of the Container
page-pfe
d. allows the programmer to specify the exact location of each GUI component with
respect to the lower-left corner of the Container
12.18 Q2: All layout managers implement the interface ________.
a. LayoutInterface
b. InterfaceLayoutManager
c. LayoutManagerInterface
d. LayoutManager
12.18 Q3: Which layout manager is the default for JFrame?
a. FlowLayout
b. BorderLayout
c. GridLayout
d. None of the above
12.18.1 FlowLayout
12.18.1 Q1: FlowLayout method changes the alignment for the FlowLayout.
a. setLayout
b. modifyAlignment
c. setAlignment
d. setAlign
12.18.1 Q2: Each container can have ________.
a. only one layout manager
b. one or more layout managers
c. zero or more layout managers
d. only one or two layout managers
12.18.1 Q3: FlowLayout is ________.
a. an abstract class
b. a way of organizing components vertically
c. the simplest layout manager
d. left-aligned by default
page-pff
12.18.2 BorderLayout
12.18.2 Q1: BorderLayout implements interface ________.
a. ActionListener
b. FlowLayout.
c. Layout
d. LayoutManager2
12.18.2 Q2: Which region is used by default when a Component is added to a
BorderLayout?
a. NORTH
b. CENTER
c. WEST
d. LEFT
12.18.3 GridLayout
12.18.3 Q1: The class GridLayout constructs to hold components.
a. a horizontal grid with one row
b. a vertical grid with one column
c. a grid with multiple rows and columns
d. a square grid with the same number of rows as columns
12.18.3 Q2: When components are added to a container with a GridLayout, the
component ________.
a. fills the next spot in the row, continuing in the first position of the next row if the
current row is full
b. fills the next spot in the column, continuing in the first position of the next column if
the column is full
c. fills in row x, column y if x and y are two integers passed to the Container method add
d. fills in a random empty position in the grid
12.19 Using Panels to Manage More Complex
page-pf10
12.19 Q1: Which of the following statements about JPanels is false?
a. A JPanel is a JComponent.
b. A JPanel is a Container.
c. A JPanel does not have a content pane.
d. A JPanel has a fixed size.
12.20 JTextArea
12.20 Q1: A JTextArea ________.
a. provides a bounding box used for the layout of JTextFields
b. wraps lines by default
c. provides an area for manipulating multiple lines of text
d. provides scrollbars for JTextFields
12.20 Q2: Class JTextArea’s getSelectedText method ________.
a. returns the text in the JTextArea
b. returns the selected text in the JTextArea
c. displays only the selected text in the JTextArea
d. sets the selected text in the JTextArea
12.20 Q3: By default JScrollPane ________.
a. always displays scrollbars
b. never displays scrollbars
c. only displays scrollbars if they are needed
d. None of the above
12.20 Q4: Which methods can be used to change the scrollbar policies?
a. setHoizontalPolicy, setVerticalPolicy.
b. setHorizontal, setVertical.
c. setHPolicy, setVPolicy.
d. setHorizontalScrollBarPolicy, setVerticalScrollBarPolicy.

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.