0% found this document useful (0 votes)
397 views11 pages

Chapter 13 Q

A text field that can be changed by code in the application is known as what? a. Write-only b. Static c. Read-only d. Formal ANS: C. The default selection mode for a JList component is: a. Single selection b. Single interval selection c. Multiple interval selection d. There is no default setting.

Uploaded by

bisratdb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
397 views11 pages

Chapter 13 Q

A text field that can be changed by code in the application is known as what? a. Write-only b. Static c. Read-only d. Formal ANS: C. The default selection mode for a JList component is: a. Single selection b. Single interval selection c. Multiple interval selection d. There is no default setting.

Uploaded by

bisratdb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 11

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

2012 Pearson Education

Chapter 13
MULTIPLE CHOICE
1. A text field that can be changed by code in the application, but cannot be edited by the user is known as what?
a. Write-only
b. Static
c. Read-only
d. Formal
ANS: C
2. What will be the results of executing the following statements?
x.setEditable(true);
x.setText("Tiny Tim");
a.
b.
c.
d.

The text field x will have the value "Tiny Tim" and be read-only.
The text field x will have the value "Tiny Tim" and the user will be able to change its value.
The text field x will have the value true.
The text field x have the value "trueTiny Tim"

ANS: B
3. Java provides this component for creating lists:
a. JColumn
b. JList
c. JPanel
d. JFrame
ANS: B
4. The default selection mode for a JList component is:
a. single selection
b. single interval selection
c. multiple interval selection
d. There is no default setting.
ANS: C
5. When an item in a Jlist object is selected it generates a(n):
a. action listener event
b. action performed event
c. list selection listener event
d. list selection event
ANS: D
6. To determine which item in a list is currently selected use:
a. the getSelectedIndex method
b. the getSelectedValue method

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

c.
d.

2012 Pearson Education

Both a and b
Neither a or b

ANS: C
7. To add the JList object addressList to a scroll pane named scrollPane, use the following
a. JScrollPane scrollPane = new JScrollPane(addressList);
b. scrollPane.add(addressList);
c. addressList.add(scrollPane);
d. addressList.addScrollPane(scrollPane);
ANS: A
8. If addressList is a JList component, what will the value of x be after the following statement is executed?
x = addressList.getSelectedIndex();
a.
b.
c.
d.

The value of the first selected item.


The index of the first selected item.
An array of objects containing the items selected.
An array containing the indices of all the selected items in the list.

ANS: B
9. When an item in the combo box is selected, the combo box executes its action event listener's
actionPerformed method, passing:
a. an ItemEvent object as an argurment.
b. a SelectionEvent object as an argurment.
c. an ActionEvent object as an argument.
d. the combo box as an argument.
ANS: C
10. If the combo box addressBox contains a list of strings, why is the returned value of getSelectedItem
method in the following code cast to String?
String selectedAddress;
selectedAddress = (String)addressBox.getSelectedItem();
a.
b.
c.
d.

This is not necessary.


Because the syntax of the method requires it.
It makes the program more readable
Because the return type of the method is an Object.

ANS: D
11. This type of combo box combines a button with a list and allows the user to select items from its list only.
a. Editable
b. Static
c. Bound
d. Uneditable

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

2012 Pearson Education

ANS: D
12. If a user enters a value in the text box of an editable combo box and the value is not in the list, what will the
method getSelectedIndex return?
a. The index of the item that the user replaced.
b. The index of the item the user entered.
c. -1
d. 0, since the item is not in the list.
ANS: C
13. The ImageIcon class supports all the following file types, except:
a. BMP
b. JPEG
c. GIF
d. PNG
ANS: A
14. What will display when the following code is executed:
JLabel label = new JLabel ("It is a beautiful morning.");
labed.setIcon(SunnyFace.gif);
a.
b.
c.
d.

A label with the text "It is a beautiful day." to the left of the SunnyFace image.
A label with the text "It is a beautiful day." to the right of the SunnyFace image.
A label with the text "It is a beautiful day." below the SunnyFace image.
A label with the text "It is a beautiful day." above the SunnyFace image.

ANS: B
15. To force the JFrame that encloses a window to resize itself automatically when a larger object is placed in the
frame, use:
a. the pack method.
b. the resize method.
c. the grow method.
d. the enlarge method.
ANS: A
16. 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 SHIFT 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 CTRL key to quickly access a
component such as a button.

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

2012 Pearson Education

ANS: C
17. To add a tool tip to a component use:
a. the setToolTipText method.
b. the addToolTipText method.
c. the toolTipText method.
d. the appendToolTipText method.
ANS: A
18. The default directory for the JFileChooser constructor is:
a. Your login directory if you are using UNIX
b. Probably My Documents if you are using Windows
c. Neither a nor b
d. Both a and b
ANS: D
19. What will happen when the following code is executed?
JPanel panel = new JPanel();
Color selectedColor;
selectedColor = JColorChooser.showDialog(null,
"Select color", Color.BLUE);
a.
b.
c.
d.

A Color Chooser will be displayed in the upper, left-hand corner of the screen with "Select color" in
its Title Bar and blue pre-selected.
A Color Chooser will be displayed in the center of the screen with "Select color" in its Title Bar and
blue pre-selected.
A Color Chooser will be displayed in the center of the screen with "Select color" as the OK button's
text and blue pre-selected.
A Color Chooser will be displayed in the lower, right-hand corner of the screen with "Select color"
in its Title Bar and blue pre-selected.

ANS: B
20. A menu system may consist of each of the following, except:
a. check box menu item
b. combo box menu item
c. radio button menu item
d. menu item
ANS: B
21. A ____________ object specifies a components width and height.
a. Container
b. Region
c. Frame
d. Dimension
ANS: D

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

2012 Pearson Education

22. Which of the following is not a class used in constructing a menu system?
a. JMenuItem
b. JCheckBoxMenuItem
c. JButton
d. JRadioButtonMenuItem
ANS: C
23. The Dimension class is part of the:
a. javax.swing.event package
b. java.awt.menu package
c. javax.swing package
d. java.awt package
ANS: D
24. What will the following code do when it is executed?
JTextArea message = JTextArea(greetings, 50, 70);
JScrollPane scrollPane = new JScrollPane(message);
a.
b.
c.
d.

It will create a JScrollPane object for the JTextArea object referenced by message and
display a horizontal scroll bar on the text area.
It will create a JScrollPane object for the JTextArea object referenced by message and
display a vertical scroll bar on the text area.
It will create a JScrollPane object for the JTextArea object referenced by message and
display both vertical and horizontal scroll bars on the text area.
It will create a JScrollPane object for the JTextArea object referenced by message and
display no scroll bars on the text area.

ANS: C
25. What will happen when the following statement is executed?
x.setEditable(false);
a.
b.
c.
d.

The boolean variable x will be set to false.


The text field x will be made read-only.
The text field x will be editable.
The boolean variable x will be editable.

ANS: B
26. When you create an instance of the JList class:
a. you pass an array of objects to the constructor.
b. the list has a default selection mode of Single Selection Mode.
c. the values in the list are automatically sorted.
d. you must indicate the maximum number of list items the user may select at any one time.
ANS: A

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

2012 Pearson Education

27. The following statement:


textList.setSelectionMode(
ListSelectModel.SINGLE_INTERVAL_SELECTION);
a.
b.
c.
d.

sets the textList component to single selection mode.


sets the textList component to ListSelectModel.
sets the textList component to single interval selection mode.
sets the value of textList to SINGLE_INTERVAL_SELECTION.

ANS: C
28. The getSelectedIndex method returns:
a. the index of the selected item.
b. -1 if no item is selected.
c. Both a and b.
d. Neither a or b.
ANS: C
29. If nameList is a JList component, use the following statement to display 4 rows in nameList.
a. nameList.setRowCount(4);
b. nameList.setDisplayRowCount(4);
c. nameList.setShowRowCount(4);
d. nameList.setVisibleRowCount(4);
ANS: D
30. If addressList exists and has values stored in it and addrList is an array with values stored in it, what will
be the results when the following code is executed?
addressList.setListData(addrList);
a.
b.
c.
d.

The values of addrList will be attached at the end of the current addressList.
The values in addressList will be replaced by the values in addrList.
The values of addrList will be inserted at the beginning of the current addressList.
addressList will be unchanged.

ANS: B
31. The JComboBox class is in the:
a. javax.swing package
b. java.awt package
c. java awt.event package
d. java.swing.event package
ANS: A
32. Images may be displayed in labels and:
a. lists
b. buttons

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

c.
d.

2012 Pearson Education

combo boxes
panels

ANS: B
33. If a user enters a value in the text box of an editable combo box and the value is not in the list, what will the
method getSelectedItem return?
a. The value that the user replaced
b. The index of the item the user entered
c. The value that appears in the text field, even if it is not in the combo box's list
d. Nothing, since the item is not in the list
ANS: C
34. The ImageIcon class constructor accepts:
a. an integer that references the image.
b. a String argument which is the name of the image file.
c. a String argument which is the name of the image.
d. it does not accept any arguments.
ANS: B
35. What will display when the following code is executed:
JButton button =
new JButton ("It is a beautiful day.");
button.setIcon(SunnyFace.gif);
a.
b.
c.
d.

A button with the text "It is a beautiful day." to the left of the SunnyFace image.
A button with the text "It is a beautiful day." to the right of the SunnyFace image.
A button with the text "It is a beautiful day." below the SunnyFace image.
A button with the text "It is a beautiful day." above the SunnyFace image.

ANS: B
36. What will display 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.
b.
c.
d.

The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
imagePanel will resize itself to accommodate the SunnyFace image.
The SunnyFace image will resize itself to fit on imageLabel.
The SunnyFace image will resize itself to fit on imagePanel.

ANS: A

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

2012 Pearson Education

37. If the letter chosen as the mnemonic is in the components text, the first occurrence of that letter will appear
____________ when the component is displayed.
a. bolded
b. italicized
c. underlined
d. All of the above
ANS: C
38. Which of the following assigns ALT+C as a mnemonic key for the JButton object, clearButton?
a. clearButton.addMnemonic(KeyEvent.VK_C);
b. clearButton.setMnemonic(KeyEvent.C);
c. clearButton.setMnemonic(KeyEvent.VK_C);
d. clearButton.assignMnemonic(KeyEvent.VK_C);
ANS: C
39. A tool tip is:
a. a guide provided by the Help menu as to which tool to use for various programming techniques.
b. another name for the Tool Bar.
c. used to make programming easier.
d. text that is displayed in a small box when the user holds the mouse cursor over a component.
ANS: D
40. This is a specialized dialog box that allows the user to select a color from a predefined palette of colors.
a. Hue picker
b. Color chooser
c. Paint dialog box
d. Palette selector
ANS: B
41. If the argument passed to the showOpenDialog method is null:
a. the dialog box will normally be displayed in the upper, left-hand corner of the screen.
b. the dialog box will normally be centered in the screen.
c. nothing will be displayed because there was nothing passed to the method.
d. -1 will be returned from the method.
ANS: B
42. What will be the results of executing the following code, if the user simply clicks OK?
JPanel panel = new JPanel();
Color selectedColor;
selectedColor = JColorChooser.showDialog(null,
"Select color", Color.blue);
panel.setForeground(selectedColor);
a.
b.

The foreground color will remain unchanged.


The foreground color will be set to white.

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

c.
d.

2012 Pearson Education

The foreground color will be set to black.


The foreground color will be set to blue.

ANS: D
43. A menu system may consist of each of the following except:
a. menu item
b. separator bar
c. menu bar
d. It may have all the above.
ANS: D
44. A menu within a menu is called what?
a. Nested menu
b. Submenu
c. Recursive menu
d. Formal list
ANS: B
45. Which of the following is not a class used in constructing a menu system?
a. JMenuItem
b. JCheckBoxMenuItem
c. JComboBoxMenuItem
d. JRadioButtonMenuItem
ANS: C
46. The JMenuBar method is a(n):
a. JFrame method
b. JPanel method
c. JMenu method
d. JTextComponent method
ANS: A
47. What does the following statement do?
JTextArea textField = JTextArea(message, 25, 15);
a.

It creates a text area with 25 columns and 15 rows that will initially display the text stored in the
String object message.

b.

It creates a text area with 25 columns and 15 rows that will initially display the text stored in the text
area textField.

c.

It creates a text area with 25 rows and 15 columns that will initially display the text stored in the
String object message.

d.

It creates a text area with 25 rows and 15 columns that will initially display the text "message".

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

2012 Pearson Education

ANS: C
48. 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 slider =
new JSlider(0, 50, 25, JSlider.HORIZONTAL);

b.

JSlider slider =
new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

c.

JSlider slider =
new JSlider(JSlider.HORIZONTAL, 25, 0, 50);

d.

JSlider slider =
new JSlider(JSlider.HORIZONTAL, 50, 0, 25);

ANS: B
TRUE/FALSE
1. Both AWT classes and Swing classes ultimately inherit from the Component class.
ANS: T
2. A read-only text field uses the JReadOnlyTextField component.
ANS: F
3. By default the scroll bars are always displayed in a JList component.
ANS: F
4. When creating images, the argument passed to the image parameter in the JLabel constructor can be an
ImageIcon object, or any object that implements the Icon interface.
ANS: T
5. In the following code the setPreferredSize method sets the size of the text, "Have a good day".
label = new Jlabel("Have a good day", SwingConstants.CENTER);
label.setPreferredSize(new Dimension(400,200));
ANS: F
6. When using a slider, by default, tick marks are not displayed, and setting their spacing does not cause them to be
displayed.
ANS: T

Gaddis: Starting Out with Java: From Control Structures through Objects, 5/e

2012 Pearson Education

7. When a JList component is added to a JScrollPane object, a border will automatically appear around the
list.
ANS: T
8. You can create a label with an image, or with both an image and text.
ANS: T
9. A label's preferred size is determined only by calling the setPreferredSize method.
ANS: F
10. When you write a change listener class method for a slider, it must implement the ChangeListener interface
which is in the javax.swing.event package.
ANS: T

You might also like