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

Question 1. In order to handle an event from a JButton object button1, what does

ID: 3560866 • Letter: Q

Question

Question 1. In order to handle an event from a JButton object button1, what does a programmer need to do?

       Create a nested inner class that implements the ActionListener interface.
       Create an object of the nested inner class as the event handler object.
       Invoke the addActionListener method on button1 to register the event handler object with the event source.
       All of the above.


Question 2. 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.

       g.drawLine(0, 0, getHeight( ), getWidth( ));
       g.drawDiagonal(0, 0, getHeight( ), getWidth( ));
       g.drawLine(0, 0, getWidth( ), getHeight( ));
       g.connectCorners(getHeight( ), getWidth( ), 0, 0);



Question 3. The Graphics class in Java provides methods to

       draw lines between any two points.
       draw text strings starting at any point.
       draw shapes such as rectangles, ovals, etc.
       All of the above.


Question 4. In order to draw an orange circle, you must first

       draw the circle and then set the color using circle.setColor(ORANGE);.
       set the color on the graphics object by doing g.setColor(Color.ORANGE);.
       set the circle color by doing circle.setColor(ORANGE);.
       set the background color to Color.ORANGE and then draw the circle.


Question 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

       implement the MouseMotionListener interface and use the MouseMotionEvent to get the position.
       implement the MouseEventListener interface and use the getX and getY methods to get the position..
       implement the MouseListener interface and use the MouseEvent object parameter to the mouseClicked method to get the position.
       implement the MouseEvent interface and use the getX and getY methods to get the position.



Question 6. In order to get an event associated with a key being typed and determine which key was typed, a Java program must

       implement the KeyListener interface and use the KeyEvent method to get the key information.
       implement the KeyBoardEvent interface and use the getKeyTyped method.
       implement the KeyListener interface and use the KeyEvent object parameter to the keyTyped method to get information about which key was typed.
       implement the KeyEvent interface and use the getKeyCode method to get the key typed.



Question 7. To catch an exception, code which causes the exception must be enclosed in a

       throws block.
       catch block.
       try block.
       finally block.



Question 8. If the requirement to catch or throw a checked exception is not satisfied

       the JVM will handle the exception with its default exception handling.
       the compiler will issue an error message indicating that the exception must be caught or thrown.
       the stack trace will be displayed indicating the exception that has occurred and where it occurred.
       the stack trace will be displayed along with a message indicating that the exception must be caught.

Question 9. If the code in a try block can generate multiple exceptions,

       the try block can be followed by multiple catch blocks, one for each exception type.
       a catch block can be set up with multiple exception parameters.
       multiple finally blocks can be added to deal with the multiple exception types.
       there is no way to deal with the different types of exceptions.


Question 10. What does the following Java statement do?

            FileInputStream stream = new FileInputStream(

Question 1. In order to handle an event from a JButton object button1, what does a programmer need to do?

       Create a nested inner class that implements the ActionListener interface.
       Create an object of the nested inner class as the event handler object.
       Invoke the addActionListener method on button1 to register the event handler object with the event source.
       All of the above.


Explanation / Answer

C

A

B

C

A

B

C

A

B

C

A

A

B

C

B

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote