Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (TCO 4) In order to handle an event from a JButton object button1, what does

ID: 3661050 • Letter: 1

Question

1. (TCO 4) In order to handle an event from a JButton object button1, what does a programmer need to do? (Points : 6) a. Create a nested inner class that implements the ActionListener interface. b. Create an object of the nested inner class as the event handler object. c. Invoke the addActionListener method on button1 to register the event handler object with the event source. d. All of the above. 2. (TCO 5) Which of the following draws a line from the upper left corner of a panel to the lower right corner of the panel? Assume g is the graphics object running in the paintComponent method of the panel. (Points : 6) a g.drawLine(0, 0, getHeight( ), getWidth( )); b g.drawDiagonal(0, 0, getHeight( ), getWidth( )); c g.drawLine(0, 0, getWidth( ), getHeight( )); d g.connectCorners(getHeight( ), getWidth( ), 0, 0); 3. (TCO 5) The x, y drawing coordinate system used in Java graphics (Points : 6) a uses character units. b has the origin in the upper left corner of the display area. c uses the x coordinate for the vertical axis. d All of the above. 4. (TCO 5) To draw a rectangle which is filled in with the color orange, you would (Points : 6) a set the color to orange on the graphics object, and then use the fillRect method to draw the rectangle. b use the fillRect method to draw the rectangle, and then set the color to orange on the graphics object. c set the color to orange on the graphics object, and then use the drawRect method to draw the rectangle. d use the drawRect method to draw the rectangle, and then set the color to orange on the graphics object. 5. (TCO 5) In order to get an event associated with a mouse click and determine the position of the mouse cursor when the click happened, a Java program must (Points : 6) a. implement the MouseMotionListener interface and use the MouseMotionEvent to get the position. b. implement the MouseEventListener interface and use the getX and getY methods to get the position.. c . implement the MouseListener interface and use the MouseEvent object parameter to the mouseClicked method to get the position. d. implement the MouseEvent interface and use the getX and getY methods to get the position. 6. (TCO 5) KeyEvents are generated whenever (Points : 6) a. a key is pressed. b. a key is released. c. a key is typed. d. All of the above. 7. (TCO 6) When an exception occurs, it is said to have been (Points : 6) a. caught. b. thrown. c. declared. d. handled. 8. (TCO 6) Which of the following statements is true? (Points : 6) a. The code in a finally block is executed only if an exception occurs. b. The code in a finally block is executed only if an exception does not occur. c. The code in a finally block is executed only if there are no catch blocks. d. The code in a finally block is executed if the try block it follows is entered. 9. (TCO 6) In the catch block below, what is arithmeticException? catch ( ArithmeticException arithmeticException ) { System.err.printf( arithmeticException ); } (Points : 6) a. The type of the exception being caught. b. A finally block. c. An exception handler. d. The name of the catch block

Explanation / Answer

1. b. Create an object of the nested inner class as the event handler object

2. (TCO 5) Which of the following draws a line from the upper left corner of a panel to the lower right corner of the panel? Assume g is the graphics object running in the paintComponent method of the panel. , getWidth( )); c g.drawLine(0, 0, getWidth( ),

3. (TCO 5) The x, y drawing coordinate system used in Java graphics (Points : 6)
c uses the x coordinate for the vertical axis.
4. (TCO 5) To draw a rectangle which is filled in with the color orange, you would (Points : 6) a set the color to orange on the graphics object, and then use the fillRect method to draw the rectangle.

5. (TCO 5) In order to get an event associated with a mouse click and determine the position of the mouse cursor when the click happened, a Java program must (Points : 6)
. b. implement the MouseEventListener interface and use the getX and getY methods to get the position..
. 6. (TCO 5) KeyEvents are generated whenever (Points : 6)
d. All of the above.
7. (TCO 6) When an exception occurs, it is said to have been
b. thrown.

8. (TCO 6) Which of the following statements is true?

. c. The code in a finally block is executed only if there are no catch blocks.
9. (TCO 6) In the catch block below, what is arithmeticException?
b. A finally block.
10. (TCO 7) What does the following Java statement do? FileOutputStream stream = new FileOutputStream(“myfile.txt”);
c. Creates an output stream for reading bytes from a file.
11. (TCO 7) What is the purpose of a BufferedInputStream?
b. It improves performance by buffering data read from the file.
12. (TCO 7) What is needed for a class to implement the Serializable interface? (Points : 6) a. The class must add code for the serialize and deserialize methods of this interface.
13. (TCO 8) Which of the following is commonly found in a class level Javadoc comment? (Points : 6)

. d. All of the above.
14. (TCO 8) What Javadoc tags are commonly used at the method level? (Points : 6)
d. All of the above.
15. (TCO 8) The command to create a Java archive needs
. c. the names of all the files to be included in the archive.