File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Image Click Event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Image Click Event" Watch "Image Click Event" New topic

Image Click Event

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Is it possible to have image click event with the use of JDK1.1.7B? Like they have button click or mouse click for the buttons.
Is anybody has demo simple applet or code?
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
You can create a canvas whatever size that you want it and have your image occupy the entire canvas. Canvas has no border or anything, so it will just look like your image. Since Canvas is a Component you can addMouseListener() and detect clicks etc.
You will have to size the canvas depending on what LayoutManager the enclosing container has.
When you sub-class Canvas, you will need to put the image on it in its paint() method.
Cindy Glass
Co-author of Java 2 Certification Passport

[This message has been edited by Cindy Glass (edited November 05, 2001).]

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: Image Click Event
It's not a secret anymore!