Exercises

  1. Review the javadoc pages for classes and interfaces in package java.awt.event. How many classes and interfaces exist?

  2. Write a program that displays a JFrame. Install a key listener and the three kinds of mouse listener on the frame. Print out each event that is received. Are you surprised at the number of mouse motion events?

  3. The source code for the event interfaces and their methods can also be reviewed in the directory $JAVAHOME/src/java/awt/event. ($JAVAHOME is the location where you installed the release. On my system it is C:jdk1.4.)

    Take a look at MouseWheelEvent.java, which shows how support for the new mouse wheels was added in JDK 1.4. What information can a mouse wheel event convey?

  4. After doing the previous exercise, design and describe the event that represents a Zap. Zaps are delivered from the new “Wendy Wand” hardware that can be pointed at any component and invoked with a wink and a shake. Zaps have a location on the screen, a Zap-strength field (wimpy, medium, stun, or to-frog), and a Zap-Color.

  5. Write a program that displays a JFrame and handles Zap events. Simulate Zap events by instantiating them and posting them to the event queue. Class java.awt.EventQueue has a method postEvent() that will do this for you. Perhaps you could make a mouse click generate a Zap event in its handler.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.72.245