Deck 13: Advanced Gui Applications
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/46
Play
Full screen (f)
Deck 13: Advanced Gui Applications
1
What will the following code do when it is executed? JTextArea message = JTextArea(greetings,50,70);
JScrollPane scrollPane = new JScrollPane(message);
A) It will create a JScrollPane object for the JTextArea object referenced by message and display a horizontal scroll bar on the text area.
B) It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical scroll bar on the text area.
C) 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.
D) It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll bars on the text area.
JScrollPane scrollPane = new JScrollPane(message);
A) It will create a JScrollPane object for the JTextArea object referenced by message and display a horizontal scroll bar on the text area.
B) It will create a JScrollPane object for the JTextArea object referenced by message and display a vertical scroll bar on the text area.
C) 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.
D) It will create a JScrollPane object for the JTextArea object referenced by message and display no scroll bars on the text area.
C
2
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) This is not necessary.
B) Because the syntax of the method requires it.
C) It makes the program more readable
D) Because the return type of the method is an Object.
SelectedAddress = (String)addressBox.getSelectedItem();
A) This is not necessary.
B) Because the syntax of the method requires it.
C) It makes the program more readable
D) Because the return type of the method is an Object.
D
3
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.
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.
C
4
To determine which item in a list is currently selected use
A) the getSelectedIndex method
B) the getSelectedValue method
C) Both a and b
D) Neither a or b
A) the getSelectedIndex method
B) the getSelectedValue method
C) Both a and b
D) Neither a or b
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
5
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.
A) the setToolTipText method.
B) the addToolTipText method.
C) the toolTipText method.
D) the appendToolTipText method.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
6
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);
A) JScrollPane scrollPane = new JScrollPane(addressList);
B) scrollPane.add(addressList);
C) addressList.add(scrollPane);
D) addressList.addScrollPane(scrollPane);
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
7
What will display when the following code is executed: JLabel label = new JLabel ("It is a beautiful morning.");
Labed.setIcon(SunnyFace.gif);
A) A label with the text "It is a beautiful day." to the left of the SunnyFace image.
B) A label with the text "It is a beautiful day." to the right of the SunnyFace image.
C) A label with the text "It is a beautiful day." below the SunnyFace image.
D) A label with the text "It is a beautiful day." above the SunnyFace image.
Labed.setIcon(SunnyFace.gif);
A) A label with the text "It is a beautiful day." to the left of the SunnyFace image.
B) A label with the text "It is a beautiful day." to the right of the SunnyFace image.
C) A label with the text "It is a beautiful day." below the SunnyFace image.
D) A label with the text "It is a beautiful day." above the SunnyFace image.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
8
What will happen when the following code is executed? JPanel panel = new JPanel();
Color selectedColor;
SelectedColor = JColorChooser.showDialog(null,
"Select color",Color.BLUE);
A) 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.
B) A Color Chooser will be displayed in the center of the screen with "Select color" in its Title Bar and blue pre-selected.
C) 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.
D) 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.
Color selectedColor;
SelectedColor = JColorChooser.showDialog(null,
"Select color",Color.BLUE);
A) 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.
B) A Color Chooser will be displayed in the center of the screen with "Select color" in its Title Bar and blue pre-selected.
C) 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.
D) 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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
9
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
A) action listener event
B) action performed event
C) list selection listener event
D) list selection event
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
10
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.
A) single selection
B) single interval selection
C) multiple interval selection
D) There is no default setting.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following is not a class used in constructing a menu system?
A) JMenuItem
B) JCheckBoxMenuItem
C) JButton
D) JRadioButtonMenuItem
A) JMenuItem
B) JCheckBoxMenuItem
C) JButton
D) JRadioButtonMenuItem
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
12
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.
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
13
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
A) check box menu item
B) combo box menu item
C) radio button menu item
D) menu item
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
14
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.
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
15
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
A) javax.swing.event package
B) java.awt.menu package
C) javax.swing package
D) java.awt package
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
16
If addressList is a JList component,what will the value of x be after the following statement is executed? x = addressList.getSelectedIndex();
A) The value of the first selected item.
B) The index of the first selected item.
C) An array of objects containing the items selected.
D) An array containing the indices of all the selected items in the list.
A) The value of the first selected item.
B) The index of the first selected item.
C) An array of objects containing the items selected.
D) An array containing the indices of all the selected items in the list.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
17
What will happen when the following statement is executed? x.setEditable(false);
A) The boolean variable x will be set to false.
B) The text field x will be made read-only.
C) The text field x will be editable.
D) The boolean variable x will be editable.
A) The boolean variable x will be set to false.
B) The text field x will be made read-only.
C) The text field x will be editable.
D) The boolean variable x will be editable.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
18
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.
A) the pack method.
B) the resize method.
C) the grow method.
D) the enlarge method.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
19
What will be the results of executing the following statements? x.setEditable(true);
X)setText("Tiny Tim");
A) The text field x will have the value "Tiny Tim" and be read only.
B) The text field x will have the value "Tiny Tim" and the user will be able to change its value.
C) The text field x will have the value true.
D) The text field x have the value "trueTiny Tim"
X)setText("Tiny Tim");
A) The text field x will have the value "Tiny Tim" and be read only.
B) The text field x will have the value "Tiny Tim" and the user will be able to change its value.
C) The text field x will have the value true.
D) The text field x have the value "trueTiny Tim"
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
20
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
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
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
21
What will display when the following code is executed: JButton button =
New JButton ("It is a beautiful day.");
Button.setIcon(SunnyFace.gif);
A) A button with the text "It is a beautiful day." to the left of the SunnyFace image.
B) A button with the text "It is a beautiful day." to the right of the SunnyFace image.
C) A button with the text "It is a beautiful day." below the SunnyFace image.
D) A button with the text "It is a beautiful day." above the SunnyFace image.
New JButton ("It is a beautiful day.");
Button.setIcon(SunnyFace.gif);
A) A button with the text "It is a beautiful day." to the left of the SunnyFace image.
B) A button with the text "It is a beautiful day." to the right of the SunnyFace image.
C) A button with the text "It is a beautiful day." below the SunnyFace image.
D) A button with the text "It is a beautiful day." above the SunnyFace image.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
22
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
23
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.
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following is not a class used in constructing a menu system?
A) JMenuItem
B) JCheckBoxMenuItem
C) JComboBoxMenuItem
D) JRadioButtonMenuItem
A) JMenuItem
B) JCheckBoxMenuItem
C) JComboBoxMenuItem
D) JRadioButtonMenuItem
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
25
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);
A) nameList.setRowCount(4);
B) nameList.setDisplayRowCount(4);
C) nameList.setShowRowCount(4);
D) nameList.setVisibleRowCount(4);
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
26
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);
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);
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
27
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);
A) clearButton.addMnemonic(KeyEvent.VK_C);
B) clearButton.setMnemonic(KeyEvent.C);
C) clearButton.setMnemonic(KeyEvent.VK_C);
D) clearButton.assignMnemonic(KeyEvent.VK_C);
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
28
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.
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
29
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) The foreground color will remain unchanged.
B) The foreground color will be set to white.
C) The foreground color will be set to black.
D) The foreground color will be set to blue.
Color selectedColor;
SelectedColor = JColorChooser.showDialog(null,
"Select color",Color.blue);
Panel.setForeground(selectedColor);
A) The foreground color will remain unchanged.
B) The foreground color will be set to white.
C) The foreground color will be set to black.
D) The foreground color will be set to blue.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
30
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.
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
31
By default the scroll bars are always displayed in a JList component.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
32
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
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
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
33
The following statement textList.setSelectionMode(
ListSelectModel.SINGLE_INTERVAL_SELECTION);
A) sets the textList component to single selection mode.
B) sets the textList component to ListSelectModel.
C) sets the textList component to single interval selection mode.
D) sets the value of textList to SINGLE_INTERVAL_SELECTION.
ListSelectModel.SINGLE_INTERVAL_SELECTION);
A) sets the textList component to single selection mode.
B) sets the textList component to ListSelectModel.
C) sets the textList component to single interval selection mode.
D) sets the value of textList to SINGLE_INTERVAL_SELECTION.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
34
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.
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
35
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".
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".
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
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) The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
B) imagePanel will resize itself to accommodate the SunnyFace image.
C) The SunnyFace image will resize itself to fit on imageLabel.
D) The SunnyFace image will resize itself to fit on imagePanel.
ImageLabel = new JLabel();
ImagePanel.Add(imageLabel);
ImageIcon sunnyFaceImage =
New ImageIcon("SunnyFace.gif");
ImageLabel.setIcon(sunnyFaceImage);
Pack();
A) The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.
B) imagePanel will resize itself to accommodate the SunnyFace image.
C) The SunnyFace image will resize itself to fit on imageLabel.
D) The SunnyFace image will resize itself to fit on imagePanel.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
37
The JMenuBar method is a(n)
A) JFrame method
B) JPanel method
C) JMenu method
D) JTextComponent method
A) JFrame method
B) JPanel method
C) JMenu method
D) JTextComponent method
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
38
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.
A) menu item
B) separator bar
C) menu bar
D) It may have all the above.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
39
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) The values of addrList will be attached at the end of the current addressList.
B) The values in addressList will be replaced by the values in addrList.
C) The values of addrList will be inserted at the beginning of the current addressList.
D) addressList will be unchanged.
A) The values of addrList will be attached at the end of the current addressList.
B) The values in addressList will be replaced by the values in addrList.
C) The values of addrList will be inserted at the beginning of the current addressList.
D) addressList will be unchanged.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
40
The JComboBox class is in the
A) javax.swing package
B) java.awt package
C) java awt.event package
D) java.swing.event package
A) javax.swing package
B) java.awt package
C) java awt.event package
D) java.swing.event package
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
41
A label's preferred size is determined only by calling the setPreferredSize method.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
42
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.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
43
When a JList component is added to a JScrollPane object,a border will automatically appear around the list.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
44
You can create a label with an image,or with both an image and text.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
45
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 46 flashcards in this deck.
Unlock Deck
k this deck
46
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));
label = new Jlabel("Have a good day",SwingConstants.CENTER);
label.setPreferredSize(new Dimension(400,200));
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck