Ch6 Verified Test Bank Graphical User Interfaces - Instructor Test Bank | Java Foundations 5e Lewis by John Lewis. DOCX document preview.
Chapter 6: Graphical User Interfaces
Multiple Choice Questions:
1) The default layout manager used by the JPanel class is the _______________________ layout.
a) flow
b) border
c) box
d) grid
e) gridBag
2) A(n) ___________________ is an object that defines a screen element used to display information or allow the user to interact with a program in a certain way.
a) GUI
b) component
c) event
d) listener
e) AWT
3) A(n) ____________________ is an object that waits for an event to occur and responds in some way when it does.
a) GUI
b) component
c) listener
d) frame
e) panel
4) A GUI is being designed that will detect and respond to a mouse event. How many methods must appear in the listener object for the event?
a) 1
b) 2
c) 3
d) 4
e) 5
5) A container is governed by a(n) __________________, which determines exactly how the components added to the panel will be displayed.
a) event
b) content pane
c) JFrame object
d) JPanel object
e) layout manager
6) Which of the following components allows the user to enter typed input from the keyboard.
a) check boxes
b) radio buttons
c) sliders
d) combo boxes
e) none of the above
7) Which of the following components allows the user to select one of several options from a "drop down" menu?
a) check boxes
b) radio buttons
c) sliders
d) combo boxes
e) none of the above
8) Which of the following layout managers organize the components from left to right, starting new rows as necessary?
a) Border Layout
b) Box Layout
c) Card Layout
d) Flow Layout
e) Grid Layout
9) Which of the following event descriptions best describes the mouse entered event?
a) The mouse button is pressed down
b) The mouse button is pressed down and released without moving the mouse in between
c) The mouse pointer is moved onto a component
d) The mouse button is released
e) The mouse is moved while the mouse button is pressed down
10) A(n) _______________________ is a graphical window that pops up on top of any currently active window so that the user can interact with it.
a) component
b) dialog box
c) event
d) listener
e) none of the above
11) Which of the following is a fundamental idea of good GUI design?
a) Know the user
b) Prevent user errors
c) Optimize user abilities.
d) Be consistent.
e) all of the above
12) Which of the following best describes a timer component?
a) it starts when a GUI component is first initialized, and ends when it is destroyed
b) it generates action events at regular intervals
c) every object has a timer, and it is implicitly activated in the constructor of the object
d) it determines the amount of time it takes to execute a method
e) a timer cannot be considered a GUI component
13) Which of the following border styles can make a component appear raised or lowered from the rest of the components?
a) line border
b) etched border
c) bevel border
d) titled border
e) matte border
14) Which of the following represents a dialog box that allows the user to select a file from a disk or other storage medium?
a) color chooser
b) disk chooser
c) tool tip chooser
d) file chooser
e) none of the above
15) Which of the following classes play a role in altering a visual aspect of a component?
a) ColorChooser
b) ToolTip
c) BorderFactory
d) ColorCreator
e) none of the above
True/False Questions:
1) A panel is displayed as a separate window, but a frame can only be displayed as part of another container.
2) Layout managers determine how components are visually presented.
3) Check boxes operate as a group, providing a set of mutually exclusive options.
4) A dialog box allows the user to select one of several options from a "drop down" menu.
5) The grid layout organizes components into a grid of rows and columns, and also allows components to span more than one cell.
6) The keyHit event is called when a key is pressed.
7) A tool tip can be assigned to any Swing component.
8) A color chooser is a dialog box.
9) When designing a GUI, the ability of the user is not an important consideration. A GUI should be designed with the lowest common denominator in mind.
10) A mnemonic is a short line of text that will appear when the cursor is rested momentarily on top of the component.
Short Answer Questions:
1) Explain the difference between check boxes and radio buttons.
2) Explain the difference between a combo box and a dialog box.
3) Give an example of a common use of a dialog box.
4) What method in what interface is used in a GUI application to detect that a user typed the letter 'Y'?
5) Write a keyPressed method that behaves as follows. If the user presses the up arrow, the method should output "You pressed up" using the System.out.println method. If the user presses the down arrow, the method should output "You pressed down" using the System.out.println method.
public void keyPressed(KeyEvent event) {
switch(event.getKeyCode()) {
case KeyEvent.VK_UP:
System.out.println("You pressed up.");
break;
case KeyEvent.VK_DOWN:
System.out.println("You pressed down.");
break;
}//end switch
}//end method
6) When, if ever, should a component be disabled?
7) Write a segment of code that will use a dialog box to ask a user to enter their age. Their age will then be stored in an int variable named userAge. Assume that the necessary import statements to support the dialog box are already in place.
int userAge;
String ageStr; // used for user's response
ageStr = JOptionPane.showInputDialog("How old are you"?);
userAge = Integer.parseInt(ageStr);
8) Write a short class that represents a panel with a single radio button that has the option "Yes" and the option "No." By default, the Yes button should be checked.
import javax.swing.*;
import java.awt.*;
public class RadioPanel extends JPanel {
private JRadioButton yes, no;
public RadioPanel() {
yes = new JRadioButton("Yes", true);
no = new JradioButton("No");
add(yes);
add(no);
} // end constructor
} // end class RadioPanel
9) Suppose we have created a class called MyGUI, which represents a GUI. Write a program that creates a JFrame object, adds a MyGUI object to the frame and makes it visible.
import javax.swing.*;
public class MyGUIDisplayer {
public static void main(String [] args) {
JFrame frame = new Jframe("My GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new MyGUI());
frame.pack();
frame.setVisible(true);
} // end main
} // end class MyGUIDisplayer
10) Write a short class that represents a panel with a single slider that has values from 0 to 250, with large tick marks in increments of 50 and small tick marks in increments of 10.
import javax.swing.*;
import java.awt.*;
public class SlidePanel extends JPanel {
private JSlider slide;
public SlidePanel() {
slide = new Jslider(JSlider.HORIZONTAL, 0, 255, 0);
slide.setMajorTickSpacing(50);
slide.setMinorTickSpacing(10);
slide.setPaintTicks(true);
slide.setPaintLabels(true);
add(slide);
} // end constructor
} // end class SlidePanel
11) Describe the areas of a border layout.
12) One of the fundamental ideas of good GUI design is to "know the user". How does "know the user" influence a GUI design?
13) What is the difference between a mnemonic and a tool tip?
14) Describe the difference between a heavyweight container and a lightweight container. Give an example of each.
15) When using a box layout, how is the orientation – horizontal or vertical box – specified?