
Timer, Inner Classes, and Anonymous Inner Classes in Java
Learn about Timer class and inner classes in Java, including how to manage activities over time with Timer class, access methods of enclosing classes with inner classes, and create anonymous inner classes within methods for object creation and definition.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Timer class and inner classes
Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate an action event periodically When a timer event takes place, timer calls actionPerformed(ActionEvent event) part of the ActionListener interface (java.awt.event) Example: TimerDemo.java
Inner classes Inner class Any class defined inside another is available to all the methods of the enclosing class Can access the members of the enclosing class Can reference the outer class using (Outerclass.this)
Anonymous inner classes Anonymous classes Often encountered within a method Combines the creation of an object with the definition Requires the inclusion of a semi-colon marking the end of expression containing the anonymous class Objects defined inside the method but outside of class Must be final before used inside anonymous class