9
SimpleClick
- // <applet code="SimpleClick" width="200" height="150"></applet>
- import java.applet.Applet;
- import java.awt.event.*;
- public class SimpleClick extends Applet implements MouseListener {
- public void init() {
- addMouseListener(this);
- }
- public void mouseClicked(MouseEvent e) {
- System.out.println("clicked!... ");
- System.out.println(e);
- }
- public void mousePressed(MouseEvent e) {
- System.out.println("pressed!... ");
- }
- public void mouseReleased(MouseEvent e) {
- System.out.println("released!... ");
- }
- public void mouseEntered(MouseEvent e) {
- System.out.println("entered!... ");
- }
- public void mouseExited(MouseEvent e) {
- System.out.println("exited!... ");
- }
- }
$ javac SimpleClick.java
$ appletviewer SimpleClick.java
Watch the output of the program while you move the pointer of the mouse in and out of the window, when you click the left button of the mouse and when you press it and hold it, move the pointer out of the window and release the button.
entered!...
exited!...
entered!...
pressed!...
released!...
clicked!...
java.awt.event.MouseEvent[MOUSE_CLICKED,(137,71),absolute(141,145),button=1,modifiers=Button1,clickCount=1] on panel0
pressed!...
exited!...
released!...
Comments