9

SimpleClick

  1. // <applet code="SimpleClick" width="200" height="150"></applet>
  2.  
  3. import java.applet.Applet;
  4. import java.awt.event.*;
  5.  
  6. public class SimpleClick extends Applet implements MouseListener {
  7.     public void init() {
  8.         addMouseListener(this);
  9.     }
  10.  
  11.     public void mouseClicked(MouseEvent e) {
  12.         System.out.println("clicked!... ");
  13.         System.out.println(e);
  14.     }
  15.  
  16.     public void mousePressed(MouseEvent e) {
  17.         System.out.println("pressed!... ");
  18.     }
  19.  
  20.     public void mouseReleased(MouseEvent e) {
  21.         System.out.println("released!... ");
  22.     }
  23.  
  24.     public void mouseEntered(MouseEvent e) {
  25.         System.out.println("entered!... ");
  26.     }
  27.  
  28.     public void mouseExited(MouseEvent e) {
  29.         System.out.println("exited!... ");
  30.     }
  31. }
$ 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

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].