Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
bouncing-ball/MoveTimer.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
36 lines (33 sloc)
1.04 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Lab 2: MoveTimer.java | |
* A subclass of javax.swing.Timer that can be used for animation. | |
* It also serves as an example of the code for an "event source" object. | |
*/ | |
public class MoveTimer extends javax.swing.Timer { | |
private Mover _mover; // peer object | |
private MoveListener _listener; | |
/** | |
* Constructor for the MoveTimer | |
*/ | |
public MoveTimer (int anInterval, Mover aMover) { | |
// Instantiate the timer with a particular interval | |
super(anInterval, null); | |
// Save the peer object | |
_mover = aMover; | |
// Register a new MoveListener with the MoveTimer | |
_listener = new MoveListener(); | |
this.addActionListener(_listener); | |
} | |
/** | |
* Internal class - MoveListener | |
*/ | |
private class MoveListener implements java.awt.event.ActionListener { | |
/** | |
* The actionPerformed method specifies what is to me accomplished when | |
* the timer ticks | |
*/ | |
public void actionPerformed(java.awt.event.ActionEvent e){ | |
_mover.move(); | |
} | |
} | |
} |