Chapter 18 Swing 2 – absolute java test bank
Download file with the answers
Chapter 18 Swing 2 - absolute java test bank
1 file(s) 78.12 KB
Not a member!
Create a FREE account here to get access and download this file with answers
Chapter 18
Swing II
Multiple Choice
1) When the user clicks any of the three standard JFrame buttons, a ___________ is generated.
(a) window listener
(b) window event
(c) window activator
(d) window deactivator
2) The class JFrame has a method named __________ that eliminates the invoking JFrame without terminating the program.
(a) close
(b) dispose
(c) eliminate
(d) None of the above
3) To by pass implementing all methods in the WindowListener interface, make the window listener a derived class of:
(a) WindowEvent
(b) ActionEvent
(c) WindowAdapter
(d) None of the above
4) Icons can be added to:
(a) JLabels
(b) JButtons
(c) JMenuItems
(d) all of the above
5) The Insets class is in the package ______________.
(a) java.awt
(b) javax.swing
(c) java.util
(d) java.lang
6) When using scroll bars, the text is viewed through a ______________ that shows only part of the text at a time.
(a) view port
(b) text area
(c) all of the above
(d) none of the above
7) An invocation of the Container class method _____________ updates components on the screen.
(a) setVisible
(b) setLayout
(c) update
(d) validate
8) An imaginary _____________ is used for drawing all shapes on the screen.
(a) bounding box
(b) view port
(c) container
(d) none of the above
9) The method paint has one parameter of type:
(a) Shape
(b) Graphics
(c) Image
(d) String
10) The Graphics class is a(n) ____________ class.
(a) discrete
(b) concrete
(c) abstract
(d) none of the above
11) All of the following are methods of the Graphics class except:
(a) drawRect
(b) fillRect
(c) coloredRect
(d) fill3DRect
12) Any change to graphics being displayed on the screen requires a call to the method ____________ to update the graphics.
(a) paint
(b) repaint
(c) update
(d) all of the above
13) You can use the Java method ______________ from the Color class to change the drawing color.
(a) changeColor
(b) getColor
(c) setColor
(d) useColor
14) All of the following are methods of the class Color except:
(a) getRed
(b) brighter
(c) darker
(d) dimmer
True/False
1) A window listener must define all the method headings in the WindowListener interface, even if some are trivial implementations.
2) The dispose method of the JFrame class terminates a Java program.
3) A view port shows only part of the text at one time.
4) If the policies for scroll bars are never set then the scroll bars will never be visible.
5) Java uses a coordinate system whose origin point (0, 0) is located at the upper-left corner of the screen area.
6) The paint method of the Graphics class can only be used with Applets.
7) The drawArc method of the Graphics class requires a starting angle. A positive starting angle indicates a clockwise direction.
8) A rounded rectangle is a rectangle whose corners have been replaced by arcs.
9) The Java Color class mixes amounts of red, green and yellow to produce any new color you might want.
10) The class JColorChooser can be used to produce a dialog window that allows you to choose a color by looking at color samples.
Short Answer/Essay
1) Write a Java statement to create an image icon for the image heart.gif.
Answer: ImageIcon heartIcon = new ImageIcon(“heart.gif”);
2) Write Java statements to add the icon created in number 1 above to a label that says “Love”.
Answer:
JLabel heartLabel = new JLabel(heartIcon);
heartLabel.setText(“Love”);
3) Write a Java statement to create a scroll pane for a text area named productDescription.
Answer: JScrollPane scrolledText = new JScrollPane(productDescription);
4) Set policies for the scroll bar created in number 3 above.
Answer:
scrolledText.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrolledText.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
5) Write a Java statement that draws a filled oval at position (150, 100) with a height of 100 and a width of 50.
Answer: g.fillOval(150, 100, 50, 100);
6) Write a Java statement that uses a Graphics object to display “Hello World” at position 50, 100.
Answer: g.drawString(“Hello World!”, 50, 100);
7) Explain the Java coordinate system for graphic objects.
Answer: When drawing objects on the screen, Java places the origin point (0,0) at the upper-left corner of the screen. The x-coordinate, also called the horizontal coordinate, is positive and increasing to the right. The y-coordinate, also called the vertical coordinate, is also positive buy increases in the downward direction. Points are measured as pixels.
Leave a reply