import objectdraw.*;
import java.awt.*;

// A program to measure the duration of mouse clicks.
public class ClickTimer extends WindowController {
    
    // location where messages should be displayed
    private final static Location TEXT_POS = new Location( 30, 50);
    
    // When the mouse button was depressed
    private double startingTime;
    // Used to display length of click
    private Text message;                
    
    // Create the Text to display the current count
    public void begin() {
        message = new Text( "Please depress and release the mouse",
                            TEXT_POS, canvas );
    }
    
    // Record the time that the button is pressed
    public void onMousePress(Location point) {
        startingTime = System.currentTimeMillis();
    }
    
    // Display the duration of the latest click
    public void onMouseRelease(Location point) {
        message.setText("You held the button down for " +
                        ( System.currentTimeMillis() - startingTime)/1000 + 
                        " seconds"     );
    }
}
