0% found this document useful (0 votes)
20 views13 pages

Starting Out With Java From Control Structures Through Data Structures 2nd Edition Gaddis Test Bank

Uploaded by

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

Starting Out With Java From Control Structures Through Data Structures 2nd Edition Gaddis Test Bank

Uploaded by

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

Full download test bank at https://testbankfan.

com

Starting Out With Java From Control Structures


Through Data Structures 2nd Edition Gaddis Test
Bank

For dowload this book click LINK below

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-data-structures-2nd-edition-
gaddis-test-bank/
OR CLICK BUTTON

DOWLOAD NOW

Download More ebooks [PDF]. Format PDF ebook download PDF KINDLE.
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Starting Out With Java From Control Structures Through


Data Structures 2nd Edition Gaddis Solutions Manual

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-data-structures-2nd-edition-gaddis-
solutions-manual/

Starting Out with Java From Control Structures through


Data Structures 3rd Edition Gaddis Test Bank

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition-gaddis-
test-bank/

Starting Out with Java From Control Structures through


Data Structures 3rd Edition Gaddis Solutions Manual

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition-gaddis-
solutions-manual/

Starting Out with Java From Control Structures through


Objects 6th Edition Gaddis Test Bank

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-objects-6th-edition-gaddis-test-bank/
Starting Out with Java From Control Structures through
Objects 7th Edition Gaddis Test Bank

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-objects-7th-edition-gaddis-test-bank/

Starting Out with Java From Control Structures through


Objects 7th Edition Gaddis Solutions Manual

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-objects-7th-edition-gaddis-solutions-
manual/

Starting Out With Java From Control Structures Through


Objects 6th Edition Gaddis Solutions Manual

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-objects-6th-edition-gaddis-solutions-
manual/

Starting Out with Java From Control Structures through


Objects 5th Edition Tony Gaddis Test Bank

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-objects-5th-edition-tony-gaddis-test-
bank/

Starting Out with Java From Control Structures through


Objects 5th Edition Tony Gaddis Solutions Manual

https://testbankfan.com/product/starting-out-with-java-from-
control-structures-through-objects-5th-edition-tony-gaddis-
solutions-manual/
Gaddis: Starting Out with Java: From Control Structures through Data Structures, 2/e © 2012 Pearson Education

Chapter 7

MULTIPLE CHOICE

1. ________ is a library of classes that do not replace ________, but provide an improved alternative for creating
GUI applications.
a. AWT, Swing
b. Swing, AWT
c. JFC, AWT
d. JFC, Swing

ANS: B

2. Programs that operate in a GUI environment must be


a. event driven
b. in color
c. dialog boxes
d. layout managers

ANS: A

3. In GUI terminology, a container that can be displayed as a window is known


as a _______________.
a. message dialog
b. buffer
c. Swing package
d. frame

ANS: D

4. To end an application, pass this as the argument to the JFrame class's setDefaultCloseOperation()
method.
a. END_ON_CLOSE
b. JFrame.END_ON_CLOSE
c. JFrame.EXIT_ON_CLOSE
d. JFrame.CLOSE_NOT_HIDE

ANS: C

5. The minimize button, maximize button, and close button on a window are sometimes referred to as
a. operations buttons
b. sizing buttons
c. decorations
d. display buttons

ANS: C

6. To use the ActionListener interface, as well as other event listener interfaces, you must have the following
import statement in your code:
a. import java.swing;
b. import java.awt;
Gaddis: Starting Out with Java: From Control Structures through Data Structures, 2/e © 2012 Pearson Education

c. import java.awt.*;
d. import java.awt.event.*;

ANS: D

7. When you write an action listener class for a JButton component, it must
a. have a method named buttonClicked
b. implement the ActionLIstener interface
c. have a method named actionPerformed which must take an argument of the ActionEvent
type
d. Both b and c.

ANS: D

8. In a Swing application, you create a frame object from the


a. Jlabel class
b. JFrame class
c. Jpanel class
d. AbstractButton class

ANS: B

9. To use the Color class, which is used to set the foreground and background of various objects, use the
following import statement
a. import java.swing;
b. import java.awt;
c. import java.awt.*;
d. import java.awt.event.*;

ANS: C

10. This layout manager arranges components in rows.


a. GridLayout
b. BorderLayout
c. FlowLayout
d. RegionLayout

ANS: C

11. This layout manager arranges components in regions named North, South, East, West, and Center.
a. GridLayout
b. BorderLayout
c. FlowLayout
d. RegionLayout

ANS: B

12. If panel references a JPanel object, which of the following statements adds the GridLayout to it?
a. panel.setLayout(new (GridLayout(2,3));
b. panel.addLayout(new (GridLayout(2,3));
Gaddis: Starting Out with Java: From Control Structures through Data Structures, 2/e © 2012 Pearson Education

c. panel.GridLayout(2,3);
d. panel.attachLayout(GridLayout(2,3));

ANS: A

13. When using the BorderLayout manager, how many components can each region hold?
a. 1
b. 2
c. 5
d. No limit

ANS: A

14. The GridLayout manager limits each cell to only one component. To put two or more components in a cell,
do this.
a. Resize the cells so they can hold more
b. You can nest panels inside the cells, and add other components to the panels
c. The statement is false. The GridLayout manager does not have this restriction
d. Resize the components to fit in the cell

ANS: B

15. Which of the following statements is not true?


a. Radio buttons are round and check boxes are square.
b. Radio buttons are often grouped together and are mutually exclusive; Check boxes are not
c. Radio buttons and check boxes both implement the ActionListener interface
d. They are all true

ANS: C

16. How many radio buttons can be selected at the same time as the result of the following code?

hours = new JRadioButton("Hours");


minutes = new JRadioButton("Minutes");
seconds = new JRadioButton("Seconds");
days = new JRadioButton("Days");
months = new JRadioButton("Months");
years = new JRadioButton("Years");
timeOfDayButtonGroup = new ButtonGroup();
dateButtonGroup = new ButtonGroup();
timeOfDayButtonGroup.add(hours);
timeOfDayButtonGroup.add(minutes);
timeOfDayButtonGroup.add(seconds);
dateButtonGroup.add(days);
dateButtonGroup.add(months);
dateButtonGroup.add(years);

a. 1
b. 2
c. 3
d. 4
Gaddis: Starting Out with Java: From Control Structures through Data Structures, 2/e © 2012 Pearson Education

ANS: B

17. Assume that radio references a JRadioButton object. To click the radio button in code, use the following
statement.
a. radio.Click();
b. Click(radio);
c. Click(radio, true);
d. radio.doClick();

ANS: D

18. The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object,
which contains several button components. If you want to add the buttons to the panel...

a. use the statement, panel.add(bGroup);


b. use the statement, bGroup.add(panel);
c. use the statement, Panel panel = new Panel(bGroup);
d. add each button to panel one at a time, e.g. panel.add(button1);

ANS: D

19. What will be the result of executing the following statement?

panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));

a. The JPanel referenced by panel will have a blue line border that is 5 millimeters thick.
b. The JPanel referenced by panel will have a blue line border that is 5 pixels thick.
c. The JPanel referenced by panel will have a blue line border that is 5 characters thick.
d. The JPanel referenced by panel will have a blue line border that is 5 inches thick.

ANS: B

20. When an application uses many components, rather than deriving just one class from the JFrame class, it is
often better to encapsulate smaller groups of related components and their event listeners into their own class. A
commonly used technique to do this is:
a. To extend a class from the JAbstractButton class to contain other components and their
related code
b. To extend a class from the JComponent class to contain other components and their related code
c. To extend a class from the JPanel class to contain other components and their related code
d. To extend a class from the JFrame class to contain other components and their related code

ANS: C

21. To include Swing and AWT components in your program, use the following import statements
a. import java.swing; import java.awt;
b. import java.swing; import javax.awt;
c. import javax.swing; import java.awt;
d. import javax.swing; import javax.awt;

ANS: C
Gaddis: Starting Out with Java: From Control Structures through Data Structures, 2/e © 2012 Pearson Education

22. These types of components are coupled with their underlying peers.
a. Lightweight
b. Featherweight
c. Middleweight
d. Heavyweight

ANS: D

23. JFC stands for


a. Java Fundamental Classes
b. Java Foundation Classes
c. Java Fundamental Core
d. Java Frame Class

ANS: B

24. When this is the argument passed to the JFrame class's setDefaultCloseOperation() method, the
application is hidden, but not closed.
a. HIDE_ON_CLOSE
b. JFrame. HIDE_ON_CLOSE
c. JFrame.EXIT_ON_CLOSE
d. JFrame.HIDE_NOT_CLOSE

ANS: B

25. This is a basic window that has a border around it, a title bar, and a set of buttons for minimizing, maximizing,
and closing the window.
a. Pane
b. Container
c. Frame
d. Dialog box

ANS: C

26. Which of the following statements creates a class that is extended from the JFrame class?
a. JFrame DerivedClass = new JFrame();
b. class JFrame DerivedClass;
c. JFrame(DerivedClass);
d. public class DerivedClass extends JFrame{}

ANS: D

27. What does the following statement do?

addButton.addActionListener(new AddButtonListener());

a. Creates an AddButtonListener object


b. Registers the addButton object as an ActionListener with the AddButtonListener
object
c. Creates an AddButtonListener object and registers the AddButtonListener object with
the addButton
Gaddis: Starting Out with Java: From Control Structures through Data Structures, 2/e © 2012 Pearson Education

d. Nothing, the statement is invalid

ANS: C

28. Event listeners must


a. implement an interface
b. be included in private inner classes
c. not receive any arguments
d. exit the application once it has handled the event

ANS: A

29. If button1 is a JButton object, which of the following statements will make its background blue?
a. button1.makeBackground(BLUE);
b. button1.setBackground(Color.BLUE);
c. button1.makeBackground(Color.BLUE);
d. button1.set.Background(BLUE);

ANS: B

30. This layout manager arranges components in five regions.


a. GridLayout
b. BorderLayout
c. FlowLayout
d. RegionLayout

ANS: B

31. Which of the following is not a rule for the FlowLayout manager?
a. Multiple components can be added to a container that uses a FlowLayout manager
b. New components will be added in a row from left to right
c. When there is no more room in a row, additional components are put on the next row
d. All of these are rules for the FlowLayout manager

ANS: D

32. When a component is added to a region in the BorderLayout manager,


a. the component retains its original size
b. it results in a compile time error, if it is too large
c. the component is stretched so it fills up the entire region
d. the region is resized to fit the component

ANS: C

33. When adding components to a container that is governed by the GridLayout manager,
a. you cannot specify a cell
b. you specify the cell with the row and column numbers in the add statement
c. you must add them starting with the lower, right cell
d. the components are added automatically by filling up the first column, then the second, etc.
Gaddis: Starting Out with Java: From Control Structures through Data Structures, 2/e © 2012 Pearson Education

ANS: A

34. Which of the following statements is not true?


a. Radio buttons are round and check boxes are square.
b. Radio buttons are often grouped together and are mutually exclusive; Check boxes are not
c. Radio buttons implement ActionListener; Check boxes implement ItemListener
d. All of these are true

ANS: D

35. Why doesn't the following code compile correctly?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ColorCheckBoxWindow extends JFrame
{
private JCheckBox greenCheckBox;
private final int WINDOW_WIDTH = 300, WINDOW_HEIGHT = 100;
public ColorCheckBoxWindow()
{
setTitle("Green Check Box");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
greenCheckBox = new JCheckBox("Green");
greenCheckBox.addItemListener(new CheckBoxListener());
setLayout(new FlowLayout());
add(greenCheckBox);
setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if (e.getSource() == greenCheckBox)
{
System.exit(0);
}
}
}
a. ColorCheckBoxWindow is not implementing the correct listener
b. The button cannot be added to the content pane
c. The itemStateChanged method cannot be coded here
d. greenCheckBox should not be a private member

ANS: C

36. Assume that the variable checkbox references a JCheckBox object. To determine whether the check box has
been selected, use the following code.
a. if (isSelected(checkBox)) {/*code to execute, if selected*/}
b. if (checkBox.isSelected()) {/*code to execute, if selected*/}
c. if (checkBox) {/*code to execute, if selected*/}
d. if (checkBox.doClick()) {/*code to execute, if selected*/}

ANS: B
Gaddis: Starting Out with Java: From Control Structures through Data Structures, 2/e © 2012 Pearson Education

37. What will be the result of executing the following statement?

panel.setBorder(BorderFactory.createTitleBorder("Title"));

a. The JPanel referenced by panel will have an etched border with the title "Title" displayed on it.
b. The JPanel referenced by panel will have an empty border with the title "Title" displayed on it.
c. The JPanel referenced by panel will have a line border with the title "Title" displayed on it.
d. The JPanel referenced by panel will have a compound border with the title "Title" displayed on
it.

ANS: A

38. When an application uses many components, instead of extending just one class from the JFrame class, a better
approach is to
a. break the application into several smaller applications
b. reconsider the design of the application
c. encapsulate smaller groups of related components and their event listeners into their own classes
d. just go ahead and do it in one large class

ANS: C

39. This is a graphic image that is displayed while an application loads into memory and starts up.
a. The Java 6 trademark screen
b. Memory usage screen
c. Blue screen of death
d. Splash screen

ANS: D

40. You would use this command at the operating system command line to execute the code in the
MyApplication class and display the graphic image Logo.jpg as a splash screen.
a. java MyApplication Logo.jpg
b. java -splash:Logo.jpg MyApplication
c. java MyApplication –splash
d. java Logo.jpg –splash:MyApplication

ANS: B

TRUE/FALSE

1. A GUI program automatically stops executing when the end of the main method is reached.

ANS: F

2. A common technique for writing an event listener class is to write it as a private inner class inside the class that
creates the GUI.

ANS: T
Gaddis: Starting Out with Java: From Control Structures through Data Structures, 2/e © 2012 Pearson Education

3. The following statement adds the FlowLayout manager to the container, centers the components, and
separates the components with a gap of 10 pixels.

setLayout(new FlowLayout());

ANS: F

4. Check boxes may be grouped in a ButtonGroup like radio buttons are.

ANS: T

5. The System.exit method will end the application.

ANS: T

6. The ActionEvent argument that is passed to an action listener's actionPerformed method is the event
object that was generated in response to an event.

ANS: T

7. The FlowLayout manager does not allow the programmer to align components.

ANS: F

8. You must use the statement import java.swing.*; in order to use the ItemListener interface.

ANS: F

9. When a splash screen is displayed, the application does not load and execute until the user clicks the splash
screen image with the mouse.

ANS: F

10. In Java, the ability to display splash screens was introduced in Java 6.

ANS: T
Another random document with
no related content on Scribd:

You might also like