The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
June 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Use MouseListener class from AWT Event package

Posted by Ivan Porty on June 24, 2000 at 11:09 AM

> In HTML, you can use the ALT attribute on the IMG tag to display
> text over top of an image when the mouse moves over the image
> (without clicking on it). I'd like to create the same effect
> but in a java applet. Is this possible? When the mouse moves
> over top of an image, I'd like a small display to come up with
> a few words of text, and then it to disappear after the mouse
> is moved off of it. How can I do this in a java applet? Thanks!


You must use MouseListener interface for java.awt.event package.
When you implement this interface in your class, you'll see
two methods: mouseEntered(MouseEvent) and mouseExited(MouseEvent)
first is called when mouse cursor is over your component, second- when cursor leaves your component.
don't forget to add listener to image component(canvas, panel), like imageCmp.addMouseListener(yourListener).



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us