Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

218 HOUR 15:Responding to User Input


Quiz



  1. Why are action events called by that name?
    A. They occur in reaction to something else.
    B. They indicate that some kind of action should be taken in response.
    C. They honor cinematic adventurer Action Jackson.

  2. What does thissignify as the argument to an addActionListener()
    method?
    A. thislistener should be used when an event occurs.
    B. thisevent takes precedence over others.
    C. this object handles the events.

  3. Which component stores user input as integers?
    A. JButton
    B. JTextFieldorJTextArea
    C. Neither A nor B


Answers



  1. B.Action events include the click of a button and the selection of an
    item from a pull-down menu.

  2. C.Thethiskeyword refers to the current object. If the name of an
    object is used as an argument instead of the thisstatement,that
    object would receive the events and be expected to handle them.

  3. B.JTextFieldandJTextAreacomponents store their values as text,
    so you must convert their values before you can use them as integers,
    floating-point numbers,or other nontext values.


Activities
If the main event of this hour didn’t provide enough action for your tastes,
interface with the following activities:

. Add a text field to the LottoMadnessapplication that works in conjunc-
tion with the Thread.sleep()statement in the LottoEventclass to
slow down the rate that drawings are conducted.
. Modify the LottoMadnessproject so it draws five numbers from 1 to 90.


To s e e J av a p r o g r a m s t h a t i m p l e m e n t t h e s e a c t i v i t i e s ,visit the book’s website
at http://www.java24hours.com.
Free download pdf