Chris Johnson, Index
Event Handling - Examples
/*
* A Simple Button
* Author: Chris Johnson (johnson@dcs.gla.ac.uk)
* Last revision date: 5/1//99
* Based on an example in D.M. Geary's GraphicJava 2nd Edition, Sun Press/
* Prentice Hall, 1997.
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class ButtonTester extends Applet
{
public void init()
{
Button button = new Button("Press here");
button.addMouseListener(new ButtonMouseListener());
add(button);
}
}
class ButtonMouseListener implements MouseListener {
public void mouseEntered(MouseEvent event){
System.out.println("Mouse enetered button ...");
}
// now for the null or no-op methods that must be included
// in the interface but which do nothing very much...
public void mouseExited (MouseEvent event){}
public void mousePressed (MouseEvent event){}
public void mouseClicked (MouseEvent event){}
public void mouseReleased (MouseEvent event){}
}