Deck 11: Advanced User Interfaces

Full screen (f)
exit full mode
Question
When adding a component to a container with the ____ layout, specify the NORTH, EAST, SOUTH, WEST, or CENTER position.

A) border
B) grid
C) grid bag
D) flow
Use Space or
up arrow
down arrow
to flip the card.
Question
What is the default layout manager of JPanel?

A) FlowLayout
B) GridLayout
C) BoxLayout
D) GridBagLayout
Question
Which class has constants called NORTH and SOUTH?

A) FlowLayout
B) BorderLayout
C) BoxLayout
D) GridLayout
Question
By default, a JPanel uses a _______ layout.

A) border
B) flow
C) grid
D) grid bag
Question
Which layout manager may change the location and size of existing components when new ones are added?
I FlowLayout
II BorderLayout
III GridLayout

A) I
B) II
C) I and III
D) II and III
Question
Which layout manager allows you to add components to it by invoking the container's add method with the component as the only argument to add.
I FlowLayout
II BorderLayout
III GridLayout

A) I
B) II
C) III
D) I and III
Question
Which layout manager constructor call would be best-suited to create a telephone handset GUI which has three rows of three keys each with labels, 1,2,3,4,5,6,7,8,9, and a fourth row with labels *, 0, and #?

A) new GridLayout(3, 4)
B) new GridLayout(4, 3)
C) new FlowLayout(4, 3)
D) new BorderLayout(3, 4)
Question
Which layout manager uses a grid so that each component will always be placed into an area of the same size?
I GridBagLayout
II BorderLayout
III GridLayout

A) I
B) II
C) III
D) I and III
Question
What is the easiest way to create complex-looking GUI layouts?
I use the GridBagLayout manager
II nest panels, each with its own layout manager
III use multiple layout managers in the same container

A) I
B) II
C) III
D) I and III
Question
The JFrame has a content pane with a default BorderLayout manager. Which method allows changing it to a FlowLayout manager?

A) setLayout
B) setFlowLayout
C) assignLayout
D) changeLayout
Question
Which layout manger would be best suited to create a simple navigation GUI with directional arrows for left, right, up, down and enter?

A) GridLayout
B) BorderLayout
C) FlowLayout
D) GridBagLayout
Question
If you want to have a tabular arrangement of components, in which columns have different sizes or one component spans multiple columns, a ____ would be appropriate.

A) grid bag layout
B) grid layout
C) flow layout
D) border layout
Question
Which layout manager allows you to add components in different orders, with the result being the same GUI appearance?
I FlowLayout
II BorderLayout
III GridLayout

A) I
B) II
C) I and III
D) II and III
Question
To create a _____ layout, you supply the number of rows and columns in the constructor, then add the components, row by row, left to right.

A) border
B) grid
C) grid bag
D) boxed
Question
Which layout manager uses a grid, but allows selected grid locations to span multiple rows or columns?
I GridBagLayout
II BorderLayout
III GridLayout

A) I
B) II
C) III
D) I and III
Question
Which layout manager places objects left-to-right, and creates a new row only if when the current row cannot accommodate another object?

A) FlowLayout
B) BorderLayout
C) BoxLayout
D) GridLayout
Question
Which layout manager places objects left-to-right, row by row into a fixed set of rows and columns?

A) FlowLayout
B) BorderLayout
C) BoxLayout
D) GridLayout
Question
In Java, each container has its own ____________________, which determines how the components are laid out.

A) container
B) layout manager
C) Swing component
D) frame manager
Question
How do you add two buttons to the south area of a frame using the BorderLayout?

A) Add them to a panel, then add the panel to the SOUTH
B) Add one to the SOUTH, then add the second one to the SOUTH
C) Add one to the SOUTH, then add the second one to the CENTER
D) Add one to the CENTER, then add the second one to the SOUTH
Question
What is the default layout manager of the content pane of a JFrame?

A) FlowLayout
B) GridLayout
C) BoxLayout
D) BorderLayout
Question
Insert the missing code in the following segment. The code intends to get the newly selected item from the combo box.
JComboBox facenameCombo = new JComboBox();
String selectedString = __________________________;

A) (String) facenameCombo.getSelected();
B) (String) facenameCombo.getSelectedItem();
C) (String) selectedString.getSelected();
D) (String) selectedString.getSelectedItem();
Question
What type does the method getSelectedItem in the JComboBox class return?

A) Object
B) String
C) JRadioButton
D) JLabel
Question
The event that is generated by a slider when its value changes is of type _____.

A) ActionEvent
B) ChangeEvent
C) ItemEvent
D) MouseEvent
Question
Which of the following GUI objects generate(s) action events?
I JComboBox
II JRadioButton
III JButton

A) I
B) I and II
C) I and III
D) I, II and III
Question
When using a combo box, the _______ displays the name of the current selection.

A) text field
B) text area
C) menu item
D) submenu item
Question
What is the container for top-level menu items?

A) menu bar
B) menu item
C) menu GUI
D) top level menus don't use containers
Question
Which GUI element allows text entry from the program user?

A) ButtonGroup
B) JComboBox
C) JSlider
D) JPanel
Question
Which method can a program use to set the selected choice in a JRadioButton?

A) set
B) setChoice
C) setSelectedItem
D) setSelected
Question
Which of the following methods returns the object that was selected in the JComboBox?

A) getSelected
B) getItem
C) getChoice
D) getSelectedItem
Question
A(n) ____ is used when you have a large set of choices.

A) combo box
B) radio button
C) check box
D) action event
Question
____________________ are round and have a black dot when selected.

A) Swing components
B) Selection buttons
C) Radio buttons
D) Check boxes
Question
What type of object can be added into a JComboBox by the addItem method?

A) Object
B) String
C) JRadioButton
D) any non-primitive type
Question
A ________ is a user-interface component with two states: checked and unchecked.

A) radio button
B) check box
C) menu item
D) submenu item
Question
Which method can a program use to set the selected choice in a JComboBox?

A) select
B) setChoice
C) setSelectedItem
D) The selection can only be set through the GUI by the user.
Question
Which of the following classes has a Boolean state that can be set or unset through the GUI?

A) JCheckBox
B) JButton
C) ButtonGroup
D) JMenuItem
Question
The statement that would add smallButton to the button group in the following code is _________.
JRadioButton smallButton = new JRadioButton("Small");
ButtonGroup group = new ButtonGroup();

A) group.add(new smallButton);
B) group.add(smallButton);
C) smallButton.add();
D) You cannot add smallButton to the button group.
Question
A ____ is a combination of a list and a text field.

A) radio button
B) combo box
C) check box
D) scroll bar
Question
When the user selects a menu item, the menu item sends a(n) ___________________.

A) ActionEvent
B) ChangeEvent
C) ItemEvent
D) MouseEvent
Question
Which of the following is not a visual component?

A) JRadioButton
B) JButton
C) ButtonGroup
D) JCheckBox
Question
Which of the following classes have a user-editable area?

A) JCheckBox
B) JComboBox
C) ButtonGroup
D) JRadioButton
Question
Consider the code snippet below:
Public class RectangleComponent extends JComponent
{
Private static final int RECTANGLE_WIDTH = 20;
Private static final int RECTANGLE_HEIGHT = 30;
Private int xLeft;
Private int yTop;
Public RectangleComponent()
{
XLeft = 0;
YTop = 0;
}
Public void paintComponent(Graphics

A) repaint();
B) public void moveRectangleBy(int dx, int dy);
C) xLeft = xLeft + dx;
YTop = yTop + dy;
D) xLeft = 0;
YTop = 0;
G) {
G)fillRect(xLeft, yTop, RECTANGLE_WIDTH, RECTANGLE_HEIGHT);
}
Public void moveRectangleBy(int dx, int dy)
{
XLeft = xLeft + dx;
YTop = yTop + dy;
Repaint();
}
}
Which statement(s) causes the rectangle to appear at an updated location?
Question
What method is required by the ChangeListener interface?

A) changeOccured
B) actionPerformed
C) stateChanged
D) sliderMoved
Question
Consider the following code snippet:
Final RectangleComponent component = new RectangleComponent();
MouseListener listener = new MousePressListener();
Component.addMouseListener(listener);
______________
Mystery.add(component);
Mystery.setSize(FRAME_WIDTH, FRAME_HEIGHT);
Mystery.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Mystery.setVisible(true);
Which of the following statements completes this code?

A) JPanel mystery = new JPanel();
B) JComponent mystery = new JComponent();
C) Frame mystery = new Frame();
D) JFrame mystery = new JFrame();
Question
What can be determined about obj from the code below?
JMenuItem menuItem = new JMenuItem("Exit");
MenuItem.addActionListener(obj);

A) The class of obj implements ActionListener
B) menuItem implements ActionListener
C) obj is of type MenuListener
D) obj is an object of an inner class
Question
What is the best way to discover the set of Swing components?

A) Randomly drag them into a visual appllication with a GUI builder
B) Write code to instantiate each component one at a time
C) Read the documentation for Swing
D) Run the SwingSet demo included in the JDK, Java Development Kit
Question
If one ChangeListener is listening for three different JSlider objects, how can we determine which of the three sliders caused the event when the code enters the stateChanged method?

A) It is not possible.
B) We can compare the sliders using the getSource method.
C) We can call the getValueIsAdjusting method.
D) We can compare the sliders using the getSliderSource method.
Question
What is the best way to start using Swing components?

A) Use a few classes with basic properties and methods, then explore API documentation
B) Learn all the classes in Swing and their inheritance hierarchies
C) Learn all the methods of the JComponent superclass before using any Swing components
D) Use a Swing component only after understanding all of its constructors
Question
Which code will create a JSlider with a range from 0 to 100, with an initial value of 50?
I new JSlider()
II new JSlider(0, 100, 50)
III new JSlider(50, 0, 100)

A) I
B) II
C) III
D) I and II
Question
The ____ class in the javax.swing package generates a sequence of events, spaced apart at even time intervals.

A) TimeClock
B) Timer
C) Clock
D) StopWatch
Question
When you use a timer, you need to define a class that implements the ____ interface.

A) TimerListener
B) TimerActionListener
C) ActionListener
D) StartTimerListener
Question
Examine the code below. What type of class is MyMenuListener?
Public JMenuItem makeMenuItem(String menuLabel)
{
JMenuItem mini = new JMenuItem(menuLabel);
Class MyMenuListener implements ActionListener
{
Public void actionPerformed(ActionEvent

A) It is an anonymous class
B) It is an inner class
C) It is a JMenuItem subclass
D) It is a JMenu class
E) {
DoSomething();
}
}
Mini.addActionListener(new MyMenuListener());
Return mi;
}
Question
The _______ interface toolkit has a large set of user-interface components.

A) GUI Builder
B) graphical user
C) Swing
D) JMenu
Question
If the makeMenuItem method is called four times, at most how many different actions can be performed by these four newly created MenuItem objects when the doSomethingElse method is called?
Public JMenuItem makeMenuItem(String menuLabel)
{
JMenuItem mi = new JMenuItem(menuLabel);
Class MyMenuListener implements ActionListener
{
Public void actionPerformed(ActionEvent

A) 1
B) 2
C) 3
D) 4
E) {
DoSomethingElse(e);
}
}
Mi)addActionListener(new MyMenuListener());
Return mi;
}
Question
The ChangeEvent class defines no methods. What makes it possible to call the getSource method on a ChangeEvent object?

A) The method is inherited from the Object class.
B) You have to code that method yourself.
C) The method is inherited from the EventObject class.
D) ChangeEvent implements the Event interface
Question
What type of event does the JSlider class generate?

A) ChangeEvent
B) ActionEvent
C) ItemEvent
D) SliderEvent
Question
If the method makeMenuItem is called four times, how many MyMenuListener objects will be created?
Public JMenuItem makeMenuItem(String menuLabel)
{
JMenuItem mi = new JMenuItem(menuLabel);
Class MyMenuListener implements ActionListener
{
Public void actionPerformed(ActionEvent

A) 1
B) 2
C) 3
D) 4
E) {
DoSomething();
}
}
Mi)addActionListener(new MyMenuListener());
Return mi;
}
Question
Which component can be added to a menu?
I JMenuBar
II JMenu
III JMenuItem

A) I
B) I and II
C) II and III
D) I, II and III
Question
The Timer class is found in the ____ package.

A) java.awt.
B) javax.awt.
C) java.swing.
D) javax.swing.
Question
Which component can generate action events?
I JMenuBar
II JMenu
III JMenuItem

A) I
B) II
C) III
D) II and III
Question
For a new programmer using the Swing JSlider component for the first time, which of these is the least important thing to know?

A) a basic way to construct a JSlider
B) what type of events it generates
C) how to write the BoundedRangeModel constructor
D) its value when an event occurs
Question
Consider the following code snippet:
Class MouseClickedListener implements ActionListener
{
Public void mouseClicked(MouseEvent event)
{
Int x = event.getX();
Int y = event.getY();
Component.moveTo(x,y);
}
}
What is wrong with this code?

A) The mouseClicked method cannot access the x and y coordinates of the mouse.
B) repaint() method was not called.
C) The class has implemented the wrong interface.
D) There is nothing wrong with this code.
Question
What does the MouseAdapter class provide?

A) The MouseAdapter class implements all of the methods of the MouseListener interface as do nothing methods.
B) The MouseAdapter class allows your program to accept input from multiple mice.
C) The MouseAdapter class implements all of the methods of the ActionListener interface as do nothing methods.
D) A class can implement the MouseAdapter class to handle mouse events.
Question
Suppose listener is an instance of a class that implements the MouseListener interface. How many methods does listener have?

A) 0
B) 1
C) 3
D) at least 5
Question
You can add a(n) _________ to a panel to make it visible.

A) component
B) JFrame
C) border
D) another panel
Question
Which of the following adds a border to the following panel?
JPanel panel = new JPanel();

A) panel.addEtchedBorder();
B) panel.addBorder(new EtchedBorder());
C) panel.add(new EtchedBorder());
D) panel.setBorder(new EtchedBorder());
Question
You wish to detect when the mouse is moved into a graphical component. Which methods of the associated MouseListener interface will provide this information?

A) mouseMoved
B) mouseEntered
C) mouseOver
D) mouseIncoming
Question
Given four JRadioButton objects in a ButtonGroup, how many radio buttons can be selected at the same time?

A) 1
B) 2
C) 4
D) 3
Question
A(n) ____ is used to capture mouse events.

A) action listener
B) event listener
C) mouse listener
D) component listener
Question
When a menu item is selected, what type of event does it send?

A) ActionEvent
B) ChangeEvent
C) ItemEvent
D) SelectionEvent
Question
If a JPanel with a BorderLayout manager contains a single component that was added to the CENTER, which parts of the JPanel does the component fill?
I North
II South
III Center
IV West
V East

A) I, II and III
B) II, IV an V
C) III, IV and V
D) I, II, III, IV and V
Question
Consider the following code snippet:
Class MyListener implements ActionListener
{
Public void actionPerformed(ActionEvent event)
{
System.out.println(event);
}
}
Timer t = new Timer(interval, listener);
T)start();
What is wrong with this code?

A) The Timer object should be declared before the MyListener class.
B) The listener must be declared as new MyListener().
C) The Timer object must be declared as final.
D) The word listener should be change to MyListener.
Question
Suppose a JPanel with a BorderLayout manager contains two components: component1, which was added to the NORTH, and component2, which was added to the SOUTH. Which parts of the JPanel will appear?
I North
II South
III Center
IV West
V East

A) I, II and III
B) II, IV an V
C) III, IV and V
D) I, II, III, IV an V
Question
What is the best first step in picking the layout managers for a set of nested panels?

A) use a single panel with a GridBagLayout manager
B) construct a set of JPanel objects
C) make a sketch of the layout
D) use multiple panels with FlowLayout managers
Question
Suppose a JPanel with a BorderLayout manager contains two components: component1, which was added to the EAST, and component2, which was added to the WEST. Which parts of the JPanel appear?
I North
II South
III Center
IV West
V East

A) I, II
B) I, II, III
C) III, IV and V
D) IV an V
Question
Use the ____ method to add a mouse listener to a component.

A) addListener
B) addMouseListener
C) addActionListener
D) addMouseActionListener
Question
A complex GUI can be created with a set of nested panels. What should determine the components that go into a single panel?

A) the type of components
B) the size of the components
C) the adjacency of the components
D) the names of the components
Question
Consider the following code snippet:
Public class MyMouseListener implements MouseListener
{
Public void mousePressed(MouseEvent event)
{
Double x;
Double y;
_______
System.out.println("x: " + x + ", y: " + y);
}
) . .
}
Which of the following statements should be filled in the blank to print out where the mouse was pressed?

A) x = event.getXposition(); y = event.getYposition();
B) x = (MouseEvent) getX(); y = (MouseEvent) getY();
C) x = event.printX(); y = event.printY();
D) x = event.getX(); y = event.getY();
Question
What features do GUI builders have to speed the development of the graphical user interface of the program?
I setting properties of dialog boxes
II automated event-handling code generation
III drag and drop of visual components

A) I
B) II
C) II and III
D) I, II and III
Question
What is the most time-effective way to build a GUI quickly and concentrate on coding the logic of the program?

A) use the GridBagLayout manager
B) use a GUI builder, such as NetBeans
C) use nested panels
D) use menus
Question
Suppose a JPanel with a BorderLayout manager contains two components: component1, which was added to the CENTER, and component2, which was added to the SOUTH. Which parts of the JPanel will appear?
I North
II South
III Center
IV West
V East

A) I, II
B) I, II, III
C) III, IV and V
D) II and III
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/91
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 11: Advanced User Interfaces
1
When adding a component to a container with the ____ layout, specify the NORTH, EAST, SOUTH, WEST, or CENTER position.

A) border
B) grid
C) grid bag
D) flow
A
2
What is the default layout manager of JPanel?

A) FlowLayout
B) GridLayout
C) BoxLayout
D) GridBagLayout
A
3
Which class has constants called NORTH and SOUTH?

A) FlowLayout
B) BorderLayout
C) BoxLayout
D) GridLayout
B
4
By default, a JPanel uses a _______ layout.

A) border
B) flow
C) grid
D) grid bag
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
5
Which layout manager may change the location and size of existing components when new ones are added?
I FlowLayout
II BorderLayout
III GridLayout

A) I
B) II
C) I and III
D) II and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
6
Which layout manager allows you to add components to it by invoking the container's add method with the component as the only argument to add.
I FlowLayout
II BorderLayout
III GridLayout

A) I
B) II
C) III
D) I and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
7
Which layout manager constructor call would be best-suited to create a telephone handset GUI which has three rows of three keys each with labels, 1,2,3,4,5,6,7,8,9, and a fourth row with labels *, 0, and #?

A) new GridLayout(3, 4)
B) new GridLayout(4, 3)
C) new FlowLayout(4, 3)
D) new BorderLayout(3, 4)
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
8
Which layout manager uses a grid so that each component will always be placed into an area of the same size?
I GridBagLayout
II BorderLayout
III GridLayout

A) I
B) II
C) III
D) I and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
9
What is the easiest way to create complex-looking GUI layouts?
I use the GridBagLayout manager
II nest panels, each with its own layout manager
III use multiple layout managers in the same container

A) I
B) II
C) III
D) I and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
10
The JFrame has a content pane with a default BorderLayout manager. Which method allows changing it to a FlowLayout manager?

A) setLayout
B) setFlowLayout
C) assignLayout
D) changeLayout
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
11
Which layout manger would be best suited to create a simple navigation GUI with directional arrows for left, right, up, down and enter?

A) GridLayout
B) BorderLayout
C) FlowLayout
D) GridBagLayout
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
12
If you want to have a tabular arrangement of components, in which columns have different sizes or one component spans multiple columns, a ____ would be appropriate.

A) grid bag layout
B) grid layout
C) flow layout
D) border layout
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
13
Which layout manager allows you to add components in different orders, with the result being the same GUI appearance?
I FlowLayout
II BorderLayout
III GridLayout

A) I
B) II
C) I and III
D) II and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
14
To create a _____ layout, you supply the number of rows and columns in the constructor, then add the components, row by row, left to right.

A) border
B) grid
C) grid bag
D) boxed
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
15
Which layout manager uses a grid, but allows selected grid locations to span multiple rows or columns?
I GridBagLayout
II BorderLayout
III GridLayout

A) I
B) II
C) III
D) I and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
16
Which layout manager places objects left-to-right, and creates a new row only if when the current row cannot accommodate another object?

A) FlowLayout
B) BorderLayout
C) BoxLayout
D) GridLayout
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
17
Which layout manager places objects left-to-right, row by row into a fixed set of rows and columns?

A) FlowLayout
B) BorderLayout
C) BoxLayout
D) GridLayout
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
18
In Java, each container has its own ____________________, which determines how the components are laid out.

A) container
B) layout manager
C) Swing component
D) frame manager
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
19
How do you add two buttons to the south area of a frame using the BorderLayout?

A) Add them to a panel, then add the panel to the SOUTH
B) Add one to the SOUTH, then add the second one to the SOUTH
C) Add one to the SOUTH, then add the second one to the CENTER
D) Add one to the CENTER, then add the second one to the SOUTH
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
20
What is the default layout manager of the content pane of a JFrame?

A) FlowLayout
B) GridLayout
C) BoxLayout
D) BorderLayout
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
21
Insert the missing code in the following segment. The code intends to get the newly selected item from the combo box.
JComboBox facenameCombo = new JComboBox();
String selectedString = __________________________;

A) (String) facenameCombo.getSelected();
B) (String) facenameCombo.getSelectedItem();
C) (String) selectedString.getSelected();
D) (String) selectedString.getSelectedItem();
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
22
What type does the method getSelectedItem in the JComboBox class return?

A) Object
B) String
C) JRadioButton
D) JLabel
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
23
The event that is generated by a slider when its value changes is of type _____.

A) ActionEvent
B) ChangeEvent
C) ItemEvent
D) MouseEvent
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following GUI objects generate(s) action events?
I JComboBox
II JRadioButton
III JButton

A) I
B) I and II
C) I and III
D) I, II and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
25
When using a combo box, the _______ displays the name of the current selection.

A) text field
B) text area
C) menu item
D) submenu item
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
26
What is the container for top-level menu items?

A) menu bar
B) menu item
C) menu GUI
D) top level menus don't use containers
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
27
Which GUI element allows text entry from the program user?

A) ButtonGroup
B) JComboBox
C) JSlider
D) JPanel
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
28
Which method can a program use to set the selected choice in a JRadioButton?

A) set
B) setChoice
C) setSelectedItem
D) setSelected
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following methods returns the object that was selected in the JComboBox?

A) getSelected
B) getItem
C) getChoice
D) getSelectedItem
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
30
A(n) ____ is used when you have a large set of choices.

A) combo box
B) radio button
C) check box
D) action event
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
31
____________________ are round and have a black dot when selected.

A) Swing components
B) Selection buttons
C) Radio buttons
D) Check boxes
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
32
What type of object can be added into a JComboBox by the addItem method?

A) Object
B) String
C) JRadioButton
D) any non-primitive type
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
33
A ________ is a user-interface component with two states: checked and unchecked.

A) radio button
B) check box
C) menu item
D) submenu item
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
34
Which method can a program use to set the selected choice in a JComboBox?

A) select
B) setChoice
C) setSelectedItem
D) The selection can only be set through the GUI by the user.
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following classes has a Boolean state that can be set or unset through the GUI?

A) JCheckBox
B) JButton
C) ButtonGroup
D) JMenuItem
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
36
The statement that would add smallButton to the button group in the following code is _________.
JRadioButton smallButton = new JRadioButton("Small");
ButtonGroup group = new ButtonGroup();

A) group.add(new smallButton);
B) group.add(smallButton);
C) smallButton.add();
D) You cannot add smallButton to the button group.
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
37
A ____ is a combination of a list and a text field.

A) radio button
B) combo box
C) check box
D) scroll bar
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
38
When the user selects a menu item, the menu item sends a(n) ___________________.

A) ActionEvent
B) ChangeEvent
C) ItemEvent
D) MouseEvent
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following is not a visual component?

A) JRadioButton
B) JButton
C) ButtonGroup
D) JCheckBox
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following classes have a user-editable area?

A) JCheckBox
B) JComboBox
C) ButtonGroup
D) JRadioButton
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
41
Consider the code snippet below:
Public class RectangleComponent extends JComponent
{
Private static final int RECTANGLE_WIDTH = 20;
Private static final int RECTANGLE_HEIGHT = 30;
Private int xLeft;
Private int yTop;
Public RectangleComponent()
{
XLeft = 0;
YTop = 0;
}
Public void paintComponent(Graphics

A) repaint();
B) public void moveRectangleBy(int dx, int dy);
C) xLeft = xLeft + dx;
YTop = yTop + dy;
D) xLeft = 0;
YTop = 0;
G) {
G)fillRect(xLeft, yTop, RECTANGLE_WIDTH, RECTANGLE_HEIGHT);
}
Public void moveRectangleBy(int dx, int dy)
{
XLeft = xLeft + dx;
YTop = yTop + dy;
Repaint();
}
}
Which statement(s) causes the rectangle to appear at an updated location?
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
42
What method is required by the ChangeListener interface?

A) changeOccured
B) actionPerformed
C) stateChanged
D) sliderMoved
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
43
Consider the following code snippet:
Final RectangleComponent component = new RectangleComponent();
MouseListener listener = new MousePressListener();
Component.addMouseListener(listener);
______________
Mystery.add(component);
Mystery.setSize(FRAME_WIDTH, FRAME_HEIGHT);
Mystery.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Mystery.setVisible(true);
Which of the following statements completes this code?

A) JPanel mystery = new JPanel();
B) JComponent mystery = new JComponent();
C) Frame mystery = new Frame();
D) JFrame mystery = new JFrame();
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
44
What can be determined about obj from the code below?
JMenuItem menuItem = new JMenuItem("Exit");
MenuItem.addActionListener(obj);

A) The class of obj implements ActionListener
B) menuItem implements ActionListener
C) obj is of type MenuListener
D) obj is an object of an inner class
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
45
What is the best way to discover the set of Swing components?

A) Randomly drag them into a visual appllication with a GUI builder
B) Write code to instantiate each component one at a time
C) Read the documentation for Swing
D) Run the SwingSet demo included in the JDK, Java Development Kit
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
46
If one ChangeListener is listening for three different JSlider objects, how can we determine which of the three sliders caused the event when the code enters the stateChanged method?

A) It is not possible.
B) We can compare the sliders using the getSource method.
C) We can call the getValueIsAdjusting method.
D) We can compare the sliders using the getSliderSource method.
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
47
What is the best way to start using Swing components?

A) Use a few classes with basic properties and methods, then explore API documentation
B) Learn all the classes in Swing and their inheritance hierarchies
C) Learn all the methods of the JComponent superclass before using any Swing components
D) Use a Swing component only after understanding all of its constructors
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
48
Which code will create a JSlider with a range from 0 to 100, with an initial value of 50?
I new JSlider()
II new JSlider(0, 100, 50)
III new JSlider(50, 0, 100)

A) I
B) II
C) III
D) I and II
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
49
The ____ class in the javax.swing package generates a sequence of events, spaced apart at even time intervals.

A) TimeClock
B) Timer
C) Clock
D) StopWatch
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
50
When you use a timer, you need to define a class that implements the ____ interface.

A) TimerListener
B) TimerActionListener
C) ActionListener
D) StartTimerListener
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
51
Examine the code below. What type of class is MyMenuListener?
Public JMenuItem makeMenuItem(String menuLabel)
{
JMenuItem mini = new JMenuItem(menuLabel);
Class MyMenuListener implements ActionListener
{
Public void actionPerformed(ActionEvent

A) It is an anonymous class
B) It is an inner class
C) It is a JMenuItem subclass
D) It is a JMenu class
E) {
DoSomething();
}
}
Mini.addActionListener(new MyMenuListener());
Return mi;
}
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
52
The _______ interface toolkit has a large set of user-interface components.

A) GUI Builder
B) graphical user
C) Swing
D) JMenu
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
53
If the makeMenuItem method is called four times, at most how many different actions can be performed by these four newly created MenuItem objects when the doSomethingElse method is called?
Public JMenuItem makeMenuItem(String menuLabel)
{
JMenuItem mi = new JMenuItem(menuLabel);
Class MyMenuListener implements ActionListener
{
Public void actionPerformed(ActionEvent

A) 1
B) 2
C) 3
D) 4
E) {
DoSomethingElse(e);
}
}
Mi)addActionListener(new MyMenuListener());
Return mi;
}
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
54
The ChangeEvent class defines no methods. What makes it possible to call the getSource method on a ChangeEvent object?

A) The method is inherited from the Object class.
B) You have to code that method yourself.
C) The method is inherited from the EventObject class.
D) ChangeEvent implements the Event interface
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
55
What type of event does the JSlider class generate?

A) ChangeEvent
B) ActionEvent
C) ItemEvent
D) SliderEvent
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
56
If the method makeMenuItem is called four times, how many MyMenuListener objects will be created?
Public JMenuItem makeMenuItem(String menuLabel)
{
JMenuItem mi = new JMenuItem(menuLabel);
Class MyMenuListener implements ActionListener
{
Public void actionPerformed(ActionEvent

A) 1
B) 2
C) 3
D) 4
E) {
DoSomething();
}
}
Mi)addActionListener(new MyMenuListener());
Return mi;
}
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
57
Which component can be added to a menu?
I JMenuBar
II JMenu
III JMenuItem

A) I
B) I and II
C) II and III
D) I, II and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
58
The Timer class is found in the ____ package.

A) java.awt.
B) javax.awt.
C) java.swing.
D) javax.swing.
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
59
Which component can generate action events?
I JMenuBar
II JMenu
III JMenuItem

A) I
B) II
C) III
D) II and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
60
For a new programmer using the Swing JSlider component for the first time, which of these is the least important thing to know?

A) a basic way to construct a JSlider
B) what type of events it generates
C) how to write the BoundedRangeModel constructor
D) its value when an event occurs
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
61
Consider the following code snippet:
Class MouseClickedListener implements ActionListener
{
Public void mouseClicked(MouseEvent event)
{
Int x = event.getX();
Int y = event.getY();
Component.moveTo(x,y);
}
}
What is wrong with this code?

A) The mouseClicked method cannot access the x and y coordinates of the mouse.
B) repaint() method was not called.
C) The class has implemented the wrong interface.
D) There is nothing wrong with this code.
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
62
What does the MouseAdapter class provide?

A) The MouseAdapter class implements all of the methods of the MouseListener interface as do nothing methods.
B) The MouseAdapter class allows your program to accept input from multiple mice.
C) The MouseAdapter class implements all of the methods of the ActionListener interface as do nothing methods.
D) A class can implement the MouseAdapter class to handle mouse events.
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
63
Suppose listener is an instance of a class that implements the MouseListener interface. How many methods does listener have?

A) 0
B) 1
C) 3
D) at least 5
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
64
You can add a(n) _________ to a panel to make it visible.

A) component
B) JFrame
C) border
D) another panel
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
65
Which of the following adds a border to the following panel?
JPanel panel = new JPanel();

A) panel.addEtchedBorder();
B) panel.addBorder(new EtchedBorder());
C) panel.add(new EtchedBorder());
D) panel.setBorder(new EtchedBorder());
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
66
You wish to detect when the mouse is moved into a graphical component. Which methods of the associated MouseListener interface will provide this information?

A) mouseMoved
B) mouseEntered
C) mouseOver
D) mouseIncoming
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
67
Given four JRadioButton objects in a ButtonGroup, how many radio buttons can be selected at the same time?

A) 1
B) 2
C) 4
D) 3
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
68
A(n) ____ is used to capture mouse events.

A) action listener
B) event listener
C) mouse listener
D) component listener
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
69
When a menu item is selected, what type of event does it send?

A) ActionEvent
B) ChangeEvent
C) ItemEvent
D) SelectionEvent
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
70
If a JPanel with a BorderLayout manager contains a single component that was added to the CENTER, which parts of the JPanel does the component fill?
I North
II South
III Center
IV West
V East

A) I, II and III
B) II, IV an V
C) III, IV and V
D) I, II, III, IV and V
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
71
Consider the following code snippet:
Class MyListener implements ActionListener
{
Public void actionPerformed(ActionEvent event)
{
System.out.println(event);
}
}
Timer t = new Timer(interval, listener);
T)start();
What is wrong with this code?

A) The Timer object should be declared before the MyListener class.
B) The listener must be declared as new MyListener().
C) The Timer object must be declared as final.
D) The word listener should be change to MyListener.
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
72
Suppose a JPanel with a BorderLayout manager contains two components: component1, which was added to the NORTH, and component2, which was added to the SOUTH. Which parts of the JPanel will appear?
I North
II South
III Center
IV West
V East

A) I, II and III
B) II, IV an V
C) III, IV and V
D) I, II, III, IV an V
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
73
What is the best first step in picking the layout managers for a set of nested panels?

A) use a single panel with a GridBagLayout manager
B) construct a set of JPanel objects
C) make a sketch of the layout
D) use multiple panels with FlowLayout managers
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
74
Suppose a JPanel with a BorderLayout manager contains two components: component1, which was added to the EAST, and component2, which was added to the WEST. Which parts of the JPanel appear?
I North
II South
III Center
IV West
V East

A) I, II
B) I, II, III
C) III, IV and V
D) IV an V
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
75
Use the ____ method to add a mouse listener to a component.

A) addListener
B) addMouseListener
C) addActionListener
D) addMouseActionListener
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
76
A complex GUI can be created with a set of nested panels. What should determine the components that go into a single panel?

A) the type of components
B) the size of the components
C) the adjacency of the components
D) the names of the components
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
77
Consider the following code snippet:
Public class MyMouseListener implements MouseListener
{
Public void mousePressed(MouseEvent event)
{
Double x;
Double y;
_______
System.out.println("x: " + x + ", y: " + y);
}
) . .
}
Which of the following statements should be filled in the blank to print out where the mouse was pressed?

A) x = event.getXposition(); y = event.getYposition();
B) x = (MouseEvent) getX(); y = (MouseEvent) getY();
C) x = event.printX(); y = event.printY();
D) x = event.getX(); y = event.getY();
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
78
What features do GUI builders have to speed the development of the graphical user interface of the program?
I setting properties of dialog boxes
II automated event-handling code generation
III drag and drop of visual components

A) I
B) II
C) II and III
D) I, II and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
79
What is the most time-effective way to build a GUI quickly and concentrate on coding the logic of the program?

A) use the GridBagLayout manager
B) use a GUI builder, such as NetBeans
C) use nested panels
D) use menus
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
80
Suppose a JPanel with a BorderLayout manager contains two components: component1, which was added to the CENTER, and component2, which was added to the SOUTH. Which parts of the JPanel will appear?
I North
II South
III Center
IV West
V East

A) I, II
B) I, II, III
C) III, IV and V
D) II and III
Unlock Deck
Unlock for access to all 91 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 91 flashcards in this deck.