Deck 12: GUI Applications–Part 2

Full screen (f)
exit full mode
Question
When an item in a Jlist object is selected, it generates a(n)

A) list selection event.
B) click event.
C) action listener event.
D) list listener event.
Use Space or
up arrow
down arrow
to flip the card.
Question
To force the JFrame that encloses a window to resize itself automatically when a larger object is placed in the frame, use the ________ method.

A) resize
B) refresh
C) pack
D) extend
Question
A tool tip is

A) used to make programming easier.
B) a guide provided by the Help menu.
C) text that is displayed in a small box when the user holds the mouse cursor over a component.
D) a key that you press while holding down the Alt key to interact with a component.
Question
What will be displayed when the following code is executed?
JLabel myLabel = new JLabel ("It's a beautiful morning!"); myLabel.setIcon(SunnyFace.gif);

A) A label will be displayed with the text "It's a beautiful morning!" appearing below the SunnyFace.gif image.
B) A label will be displayed with the text "It's a beautiful morning!" appearing above the SunnyFace.gif image.
C) A label will be displayed with the text "It's a beautiful morning!" appearing to the left of the SunnyFace.gif image.
D) A label will be displayed with the text "It's a beautiful morning!" appearing to the right of the SunnyFace.gif image.
Question
What will be the result when the following code is executed if addressList exists and has values stored in it, and addrList is an array with values stored in it?
AddressList.setListData(addrList);

A) The values contained in the addrList array will be appended to the end of the existing values in addressList.
B) The values contained in the addrList array will be inserted at the beginning of the existing values in addressList.
C) The values in addressList will be unchanged.
D) The values in addressList will be replaced by the values in addrList.
Question
What is the default directory for the JFileChooser constructor when you pass a String containing a valid path as an argument?

A) If you are using Windows, this will probably be the "My Documents" folder under your account.
B) If you are using UNIX, this will be your login directory.
C) Both A and B
D) None of the above
Question
Which of the following file types is not supported by the ImageIcon class?

A) JPEG
B) GIF
C) BMP
D) PNG
Question
What will be the result when the following code is executed?
ImagePanel = new JPanel();
ImageLabel = new JLabel();
ImagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif"); imageLabel.setIcon(sunnyFaceImage);
Pack();

A) The image will resize itself to fit the label.
B) The image will resize itself to fit the panel.
C) The panel will resize itself to accommodate the image.
D) The JFrame that encloses the window will resize itself to accommodate the image.
Question
A mnemonic is

A) a single key on the keyboard that you press to quickly access a component such as a button.
B) a key on the keyboard that you press in combination with the Ctrl key to quickly access a component such as a button.
C) a key on the keyboard that you press in combination with the Alt key to quickly access a component such as a button.
D) a key on the keyboard that you press in combination with the Shift key to quickly access a component such as a button.
Question
What is returned by the JList class's getSelectedIndex method?

A) the index of the selected item
B) -1 if no item is selected
C) Both A and B
D) None of the above
Question
Which of the following statements creates a horizontal slider component with a minimum value of 0, a maximum value of 50, and an initial value of 25?

A) JSlider hSlider = new JSlider(0, 50, 25, JSlider.HORIZONTAL);
B) JSlider hSlider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);
C) JSlider hSlider = new JSlider(0, 50, JSlider.HORIZONTAL, 25);
D) JSlider hSlider = new JSlider(0, JSlider.HORIZONTAL, 50, 25);
Question
If null is passed as an argument to the JFileChooser class's showOpenDialog method,

A) the dialog box will be created in memory, but it will not be displayed.
B) the dialog box will be displayed in the lower-right corner of the screen.
C) the dialog box will be displayed in the upper-left corner of the screen.
D) the dialog box will be displayed in the center of the screen.
Question
What will be the result of the following code if the user simply clicks OK?
JPanel panel = new JPanel();
Color selectedColor;
SelectedColor =
JColorChooser.showDialog(null, "Select a Color", Color.BLUE);
Panel.setForeground(selectedColor);

A) The foreground color will remain unchanged.
B) The foreground color will be set to blue.
C) The foreground color will be set to black.
D) The foreground color will be set to white.
Question
The JComboBox class is in this package.

A) javax.swing
B) java.awt.event
C) java.swing.event
D) java.awt
Question
If you call the JTextField component's setEditable method and pass false as the argument, then the text field becomes

A) unbound.
B) editable.
C) invisible.
D) read-only.
Question
When you create an instance of the JList class,

A) the text field will be editable.
B) you pass an array of objects to the constructor.
C) you must indicate the maximum number of list items the user may select at any one time.
D) you must indicate a selection mode.
Question
If nameList is an instance of a JList component, which of the following statements would display 4 rows in nameList.

A) nameList.setDisplayRowCount(4);
B) nameList.setShowRowCount(4);
C) nameList.setVisibleRowCount(4);
D) nameList.setRowCount(4);
Question
Which of the following statements adds the JList object referenced by namesList to the JScrollPane object referenced by namesListScrollPane?

A) JScrollPane namesListScrollPane = new JScrollPane(namesList);
B) namesList.addScrollPane(namesListScrollPane);
C) namesList.add(namesListScrollPane);
D) namesListScrollPane.add(namesList);
Question
If myList is a JList component, what will the value of item be after the following statement is executed?
Item = myList.getSelectedIndex();

A) The value of the first selected item in the list.
B) An array of objects containing all the selected items in the list.
C) An array containing the indices of all the selected items in the list.
D) The index of the first selected item in the list.
Question
A ________ is a collection of commands organized in one or more drop-down menus.

A) menu system
B) command list
C) main menu
D) drop-down list
Question
If multiple items have been selected in a list component, you should use the getSelectedValues or getSelectedIndices methods to retrieve the selected items.
Question
The default selection mode for a JList component is

A) single selection mode.
B) multiple interval selection mode.
C) multiple selection mode.
D) single interval selection mode.
Question
Just like regular radio button components, you must group radio button menu items in a button group in order to create a mutually exclusive relationship between them.
Question
You can create a label with an image or text, but you cannot create a label with both an image and text.
Question
To add a component to a scroll pane, you must pass a reference to the component as an argument to the JScrollPane constructor.
Question
If you assign the same mnemonic to more than one component in a window, it works only for the first component that you assigned it to.
Question
To change an application's look and feel, you call this static method of the UIManager class.

A) setLookAndFeel
B) getLookAndFeel
C) addLookAndFeel
D) showLookAndFeel
Question
You assign a tool tip to a component with the ________ method, which is inherited from the JComponent class.

A) setToolTipText
B) setToolTip
C) addToolTip
D) getToolTipText
Question
After you create a menu item, you must add it to a JMenu component in order for it to be displayed on the menu.
Question
The Dimension class is part of the ________ package.

A) java.awt.menu
B) javax.swing.event
C) javax.swing
D) java.awt
Question
The indices for a list or combo box start at 1, not 0.
Question
Which of the following is not a class used in constructing a menu system?

A) JRadioButtonMenuItem
B) JCheckBoxMenuItem
C) JButton
D) JMenuItem
Question
Which of the following statements assigns the C key as the mnemonic for the JButton object referenced by clearButton?

A) clearButton.addMnemonic(KeyEvent.VK_C);
B) clearButton.setMnemonic(KeyEvent.C);
C) clearButton.assignMnemonic(KeyEvent.VK_C);
D) clearButton.setMnemonic(KeyEvent.VK_C);
Question
The ListSelectionListener interface is in the ________ package.

A) javax.swing.event
B) java.awt
C) java.awt.event
D) java.swing
Question
What type of event is generated by a slider component when the knob's position is moved?

A) change event
B) move event
C) slide event
D) traverse event
Question
To give a combo box a text field, you must call the setEditable method and pass false as an argument.
Question
The appearance of a particular system's GUI is known as its

A) art style.
B) user interface.
C) look and feel.
D) system aesthetics.
Question
The JList and JTextArea components do not automatically display scroll bars.
Question
What does the following statement do?
JTextArea textField = JTextArea(message, 25, 15);

A) It creates a text area with 25 rows and 15 columns that will initially display the text "message."
B) It creates a text area with 25 columns and 15 rows that will initially display the text stored in the String object referenced by message.
C) It creates a text area with 25 columns and 15 rows that will initially display the text stored in the JTextArea object referenced by textField.
D) It creates a text area with 25 rows and 15 columns that will initially display the text stored in the String object referenced by message.
Question
When using a slider, by default, tick marks are not displayed, and setting their spacing does not cause them to be displayed.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 12: GUI Applications–Part 2
1
When an item in a Jlist object is selected, it generates a(n)

A) list selection event.
B) click event.
C) action listener event.
D) list listener event.
A
2
To force the JFrame that encloses a window to resize itself automatically when a larger object is placed in the frame, use the ________ method.

A) resize
B) refresh
C) pack
D) extend
C
3
A tool tip is

A) used to make programming easier.
B) a guide provided by the Help menu.
C) text that is displayed in a small box when the user holds the mouse cursor over a component.
D) a key that you press while holding down the Alt key to interact with a component.
C
4
What will be displayed when the following code is executed?
JLabel myLabel = new JLabel ("It's a beautiful morning!"); myLabel.setIcon(SunnyFace.gif);

A) A label will be displayed with the text "It's a beautiful morning!" appearing below the SunnyFace.gif image.
B) A label will be displayed with the text "It's a beautiful morning!" appearing above the SunnyFace.gif image.
C) A label will be displayed with the text "It's a beautiful morning!" appearing to the left of the SunnyFace.gif image.
D) A label will be displayed with the text "It's a beautiful morning!" appearing to the right of the SunnyFace.gif image.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
What will be the result when the following code is executed if addressList exists and has values stored in it, and addrList is an array with values stored in it?
AddressList.setListData(addrList);

A) The values contained in the addrList array will be appended to the end of the existing values in addressList.
B) The values contained in the addrList array will be inserted at the beginning of the existing values in addressList.
C) The values in addressList will be unchanged.
D) The values in addressList will be replaced by the values in addrList.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
What is the default directory for the JFileChooser constructor when you pass a String containing a valid path as an argument?

A) If you are using Windows, this will probably be the "My Documents" folder under your account.
B) If you are using UNIX, this will be your login directory.
C) Both A and B
D) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following file types is not supported by the ImageIcon class?

A) JPEG
B) GIF
C) BMP
D) PNG
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
What will be the result when the following code is executed?
ImagePanel = new JPanel();
ImageLabel = new JLabel();
ImagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage = new ImageIcon("SunnyFace.gif"); imageLabel.setIcon(sunnyFaceImage);
Pack();

A) The image will resize itself to fit the label.
B) The image will resize itself to fit the panel.
C) The panel will resize itself to accommodate the image.
D) The JFrame that encloses the window will resize itself to accommodate the image.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
A mnemonic is

A) a single key on the keyboard that you press to quickly access a component such as a button.
B) a key on the keyboard that you press in combination with the Ctrl key to quickly access a component such as a button.
C) a key on the keyboard that you press in combination with the Alt key to quickly access a component such as a button.
D) a key on the keyboard that you press in combination with the Shift key to quickly access a component such as a button.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
What is returned by the JList class's getSelectedIndex method?

A) the index of the selected item
B) -1 if no item is selected
C) Both A and B
D) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following statements creates a horizontal slider component with a minimum value of 0, a maximum value of 50, and an initial value of 25?

A) JSlider hSlider = new JSlider(0, 50, 25, JSlider.HORIZONTAL);
B) JSlider hSlider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);
C) JSlider hSlider = new JSlider(0, 50, JSlider.HORIZONTAL, 25);
D) JSlider hSlider = new JSlider(0, JSlider.HORIZONTAL, 50, 25);
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
If null is passed as an argument to the JFileChooser class's showOpenDialog method,

A) the dialog box will be created in memory, but it will not be displayed.
B) the dialog box will be displayed in the lower-right corner of the screen.
C) the dialog box will be displayed in the upper-left corner of the screen.
D) the dialog box will be displayed in the center of the screen.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
What will be the result of the following code if the user simply clicks OK?
JPanel panel = new JPanel();
Color selectedColor;
SelectedColor =
JColorChooser.showDialog(null, "Select a Color", Color.BLUE);
Panel.setForeground(selectedColor);

A) The foreground color will remain unchanged.
B) The foreground color will be set to blue.
C) The foreground color will be set to black.
D) The foreground color will be set to white.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
The JComboBox class is in this package.

A) javax.swing
B) java.awt.event
C) java.swing.event
D) java.awt
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
If you call the JTextField component's setEditable method and pass false as the argument, then the text field becomes

A) unbound.
B) editable.
C) invisible.
D) read-only.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
When you create an instance of the JList class,

A) the text field will be editable.
B) you pass an array of objects to the constructor.
C) you must indicate the maximum number of list items the user may select at any one time.
D) you must indicate a selection mode.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
If nameList is an instance of a JList component, which of the following statements would display 4 rows in nameList.

A) nameList.setDisplayRowCount(4);
B) nameList.setShowRowCount(4);
C) nameList.setVisibleRowCount(4);
D) nameList.setRowCount(4);
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following statements adds the JList object referenced by namesList to the JScrollPane object referenced by namesListScrollPane?

A) JScrollPane namesListScrollPane = new JScrollPane(namesList);
B) namesList.addScrollPane(namesListScrollPane);
C) namesList.add(namesListScrollPane);
D) namesListScrollPane.add(namesList);
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
If myList is a JList component, what will the value of item be after the following statement is executed?
Item = myList.getSelectedIndex();

A) The value of the first selected item in the list.
B) An array of objects containing all the selected items in the list.
C) An array containing the indices of all the selected items in the list.
D) The index of the first selected item in the list.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
A ________ is a collection of commands organized in one or more drop-down menus.

A) menu system
B) command list
C) main menu
D) drop-down list
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
If multiple items have been selected in a list component, you should use the getSelectedValues or getSelectedIndices methods to retrieve the selected items.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
The default selection mode for a JList component is

A) single selection mode.
B) multiple interval selection mode.
C) multiple selection mode.
D) single interval selection mode.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
Just like regular radio button components, you must group radio button menu items in a button group in order to create a mutually exclusive relationship between them.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
You can create a label with an image or text, but you cannot create a label with both an image and text.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
To add a component to a scroll pane, you must pass a reference to the component as an argument to the JScrollPane constructor.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
If you assign the same mnemonic to more than one component in a window, it works only for the first component that you assigned it to.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
To change an application's look and feel, you call this static method of the UIManager class.

A) setLookAndFeel
B) getLookAndFeel
C) addLookAndFeel
D) showLookAndFeel
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
You assign a tool tip to a component with the ________ method, which is inherited from the JComponent class.

A) setToolTipText
B) setToolTip
C) addToolTip
D) getToolTipText
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
After you create a menu item, you must add it to a JMenu component in order for it to be displayed on the menu.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
The Dimension class is part of the ________ package.

A) java.awt.menu
B) javax.swing.event
C) javax.swing
D) java.awt
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
The indices for a list or combo box start at 1, not 0.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following is not a class used in constructing a menu system?

A) JRadioButtonMenuItem
B) JCheckBoxMenuItem
C) JButton
D) JMenuItem
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following statements assigns the C key as the mnemonic for the JButton object referenced by clearButton?

A) clearButton.addMnemonic(KeyEvent.VK_C);
B) clearButton.setMnemonic(KeyEvent.C);
C) clearButton.assignMnemonic(KeyEvent.VK_C);
D) clearButton.setMnemonic(KeyEvent.VK_C);
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
The ListSelectionListener interface is in the ________ package.

A) javax.swing.event
B) java.awt
C) java.awt.event
D) java.swing
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
What type of event is generated by a slider component when the knob's position is moved?

A) change event
B) move event
C) slide event
D) traverse event
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
To give a combo box a text field, you must call the setEditable method and pass false as an argument.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
The appearance of a particular system's GUI is known as its

A) art style.
B) user interface.
C) look and feel.
D) system aesthetics.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
The JList and JTextArea components do not automatically display scroll bars.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
What does the following statement do?
JTextArea textField = JTextArea(message, 25, 15);

A) It creates a text area with 25 rows and 15 columns that will initially display the text "message."
B) It creates a text area with 25 columns and 15 rows that will initially display the text stored in the String object referenced by message.
C) It creates a text area with 25 columns and 15 rows that will initially display the text stored in the JTextArea object referenced by textField.
D) It creates a text area with 25 rows and 15 columns that will initially display the text stored in the String object referenced by message.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
When using a slider, by default, tick marks are not displayed, and setting their spacing does not cause them to be displayed.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.