Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

making a button clickable

 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you make a button clickable? Or I guess it's more of how do you make an image clickable? I can't remember at all, and can't seem to find the answer anywhere.
Thanks!
Annette
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Annette,
Do you mean in HTML, JavaScript, or Java? In HTML all you would have to do is define the image as a link (i.e. inside anchor tags), in Java you would want to use the MouseClicked(MouseEvent e) method of the MouseListener interface and test that the mouse was clicked within the x,y cooridinates of the image (or make a subclass of image that implements MouseListener and have it listen for it's own events... or make some kind of ImageButtonManager that takes an array of all your images, their coordinates, and handles mouse clicks inside them... or any other way that works for you...). I haven't used JavaScript as much, but I think that you would define a JavaScript function that does what you want the button to do (i.e. open a link, submit a form, etc.) then use the JavaScript modifier onmousedown = "theFunction()" inside the img tag of your button...
Anyway, HTH,
-Nate
 
Venkat Reddy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(In HTML)
For a clickable image pls see the following code
<a href="http://www.vistavox.com/totp/vote1.cgi">
<img src="www.bbc.co.uk/totp/index.shtml/*.gif">
</a>
URLs are just examples.
Hope this helps
Venkat
[This message has been edited by Venkat Reddy (edited February 13, 2001).]
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys!
I just needed it in plain html. I didn't realize it was as simple as putting the img tag in between the anchor tags. I thought there was another parameter to the anchor tag or something.
Anyway, thanks again!
Annette
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more questions. I seem to have it working, except for the fact that you cannot see the pictures. All you see is the generic picture frame type box that tells you a picture is supposed to go there. My original pictures were .gif, and I thought maybe it was because of that. I've tried .jpg.
any ideas as to why the pictures aren't showing up?
Annette
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to type the name and path of the image exactly as it is. So if you were working on a file named index.html and the image was in an images directory, with that directory being in the same folder as your index file, you would reference it as this:
<img src="images/imageName.gif" height="10" widht="10" border="0" alt="This is the image">
Bill
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks. I thought I had done that, but it doesn't seem to work. Would specifying a width and a height help? (Maybe I just had bad pictures or something!!).
I'll try it again.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try dragging the picture into a browser and if you see the image, then the picture is working. height and width won't do anything except stretch or shrink it. If you don't specify one, it will default to the default height and width. The name of the image and the path is what is key. If you are not seeing the image and the image is valid, then your naming or path to it is wrong.
Feel free to post you code and tell us where the image is and we can see if we see something.
Bill
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! Me again.
I decided to put the whole button thing aside for a couple of days while I "attempted" something else, but that's another story all together. Now I'm back to the button thing, and I'm about to pull my hair out because it should be so simple. Here's my code, which is out of my servlet.

Don't know how easy it is to read there, since the lines are sort of long, but if you can see something that's not right, can you let me know!
thanks so much!
Annette
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic