TouchyWindow Applet

Demonstrates event handling by creating a text box on the canvas when the mouse is clicked,

and clearing the canvas when the mouse is released.


Your browser is ignoring the <APPLET> tag!


 

Source Code:

 

import objectdraw.*;

import java.awt.*;

 

/**

 * Demonstrates event-handling.  When the mouse is pressed in the window

 * a text box is created that says "I'm touched".  The window is cleared

 * when the mouse is released.

 *

 * Lisa Ballesteros adapted from Java: An Eventful Approach

 * March 3, 2009

 */

public class TouchyWindow extends WindowController {

 

    public void onMousePress ( Location point ) {

        new Text("I’m touched", 40, 50, canvas );

    }

   

    public void onMouseRelease( Location point ) {

        canvas.clear();

    }

}