/* You might want to create yourself areas where
the user can click insteadof using buttons. Somtimes your whole applet
will have to be clickable and that iswhere the MouseListener comes in.We are going to create an applet that will show
where the user has clicked,that will also tell if he clicked on a hotspot
and if the mouse is in the appletor not.*/

// When the user clicks this will show
the coordinates of the click // at the place of the click.g.drawString("("+xpos+","+ypos+")",xpos,ypos);

// If the click was in the rectangle show
this messageif (rect1Clicked)
g.drawString("You clicked in the Rectangle",20,120); // else this oneelse g.drawString("You
clicked outside of the rectangle",20,120);

if (mouseEntered)
g.drawString("Mouse is in the applet area",20,160); else g.drawString("Mouse is outside the
Applet area",20,160);}

/* These methods always have to present when you
implement MouseListener

// This is called when the mous has been
pressed public void mousePressed (MouseEvent me)
{}

// When it has been released // not that a click also calls these Mouse-Pressed
and Released. // since they are empty nothing hapens
here. public void mouseReleased (MouseEvent me)
{}

// This is executed when the mouse enters
the applet. it will only // be executed again when the mouse has
left and then re-entered.public void
mouseEntered (MouseEvent me) { // Will draw the "inside applet message"mouseEntered
= true; repaint(); }

/* So now you can use the MouseListener instead
of Buttons. These methods will be ones that you willoften use. These methods are good for mouseClicks,
but when you need mouseOvers like in Javascriptthen you'll need the MouseMotionListener.Go to MouseMotionExample.java*/