// This example is from the book Developing Java Beans by Robert Englander.
// Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.
// Chapter 2 -- The ExampleApplet1 class
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
// the applet class definition
public class ExampleApplet1 extends Applet
implements ActionListener, // to receive action events
MouseListener // to receive mouse events
{
// the button
protected Button theButton;
// the applet initialization
public void init()
{
// add the button to the applet
theButton = new Button("Press Me");
add(theButton);
// make this applet an action listener
theButton.addActionListener(this);
// make this applet a mouse listener
theButton.addMouseListener(this);
}
// this gets called when the button is pressed
public void actionPerformed(ActionEvent e)
{
System.out.println("Button Pressed");
}
// this gets called when the mouse pointer enters the button
public void mouseEntered(MouseEvent e)
{
System.out.println("Mouse Entered");
}
// the gets called when the mouse pointer exits the button
public void mouseExited(MouseEvent e)
{
System.out.println("Mouse Exited");
}
// this gets called on a mouse click over the button.
// this is NOT the same as a button click, which results in
// an action event being generated
public void mouseClicked(MouseEvent e)
{
}
// this gets called when a mouse button is pressed over the button
public void mousePressed(MouseEvent e)
{
}
// this gets called when a mouse button is released over the button
public void mouseReleased(MouseEvent e)
{
}
}
|