This exercise is to demonstrate simple Event handling in Java GUI. Buttons are source of ActionEvent. Clicking a button invokes the actionPerformed method on the registered listeners. In this implementation, it will invoke getActionCommand() which by default returns the label of the button. The program also uses the event.getWhen() to return the time in long when the event was generated
This implementation also uses an inner class to create listener instance.
Exercise: Write a program that creates two buttons and print event information when clicked!
The OK button is clicked at Mon Nov 26 05:52:43 IST 2012 The Cancel button is clicked at Mon Nov 26 05:52:46 IST 2012 The Cancel button is clicked at Mon Nov 26 05:52:47 IST 2012 The OK button is clicked at Mon Nov 26 05:52:49 IST 2012 The OK button is clicked at Mon Nov 26 06:01:12 IST 2012
Download Code: Event Demo
No comments:
Post a Comment