Skip to main content

It’s the Event of the Year: Events in Swing Applications

  • Chapter
  • First Online:
Book cover Swing for Jython
  • 888 Accesses

Abstract

I have been referencing events, of all sorts, in many of the preceding chapters. It seems like a good time to take a better look at how events are handled in Swing applications.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 44.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 59.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    See http://docs.oracle.com/javase/8/docs/api/allclasses-noframe.html .

  2. 2.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/JButton.html .

  3. 3.

    See http://docs.oracle.com/javase/8/docs/api/java/awt/event/ActionListener.html .

  4. 4.

    See http://docs.oracle.com/javase/8/docs/api/java/awt/event/ActionEvent.html .

  5. 5.

    The primary exception was shown in Table 6-2, where there were more than a dozen listeners for the JTextArea class.

  6. 6.

    See http://docs.oracle.com/javase/8/docs/api/java/awt/event/MouseListener.html .

  7. 7.

    It's interesting to note that, at least at the time of this writing, the version 7 java.awt.event.MouseListener Javadoc page has a bad link. The “Tutorial: Writing a Mouse Listener” link should actually point to http://docs.oracle.com/javase/tutorial/uiswing/events/mouselistener.html . This bad link has been corrected on the version 8 page.

  8. 8.

    See http://docs.oracle.com/javase/8/docs/api/java/awt/event/MouseMotionListener.html .

  9. 9.

    See http://docs.oracle.com/javase/8/docs/api/java/awt/event/MouseAdapter.html .

  10. 10.

    See http://docs.oracle.com/javase/8/docs/api/java/awt/event/KeyListener.html .

  11. 11.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/JComponent.html#requestFocus%28%29 .

  12. 12.

    See http://docs.oracle.com/javase/8/docs/api/java/awt/event/KeyAdapter.html .

  13. 13.

    Initially, I mistakenly used the keyTyped(...) method, thinking that it would be the one invoked after the keystroke had been processed. But I was wrong. Fortunately, it was a trivial thing to change the name of the routine from keyTyped(...) to keyReleased(...).

  14. 14.

    See https://docs.oracle.com/javase/tutorial/uiswing/ .

  15. 15.

    See http://docs.oracle.com/javase/tutorial/uiswing/events/componentlistener.html .

  16. 16.

    See http://docs.oracle.com/javase/tutorial/uiswing/examples/events/ComponentEventDemoProject/src/events/ComponentEventDemo.java .

  17. 17.

    Thanks to Jeff Emanuel for providing this explanation on the jython-users mailing list.

  18. 18.

    This is why my version of the script includes a counter showing the number of events that have been encountered.

  19. 19.

    See http://docs.oracle.com/javase/8/docs/api/java/awt/event/ComponentAdapter.html .

  20. 20.

    If you are unfamiliar with the backtic operator, it converts the expression within as a printable string. See the Jython repr() built-in function.

  21. 21.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/JFormattedTextField.html .

  22. 22.

    See http://docs.oracle.com/javase/8/docs/api/java/beans/PropertyChangeListener.html .

  23. 23.

    See http://docs.oracle.com/javase/8/docs/api/javax/swing/InputVerifier.html .

  24. 24.

    In spite of the fact that the Javadoc for this class doesn’t identify this fact, at least not explicitly in the “Field Summary” section.

  25. 25.

    See http://docs.oracle.com/javase/8/docs/api/java/beans/PropertyChangeEvent.html .

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2015 Robert A. Gibson

About this chapter

Cite this chapter

Gibson, R.A. (2015). It’s the Event of the Year: Events in Swing Applications. In: Swing for Jython. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0817-5_14

Download citation

Publish with us

Policies and ethics