aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to code a button with image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to code a button with image" Watch "How to code a button with image" New topic
Author

How to code a button with image

rose deng
Ranch Hand

Joined: Dec 29, 2000
Posts: 78
Hi.
I want to have a button with image background,but i don't want to use Swing.
How to?
Thanks your answer in advance.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Rose,
Basically, all you have to do is extend Component, Button, Panel, Canvas... any of the AWT types you could use to draw an image on... you would send the image into your new class via the constructor, or a set method, and have the new component paint the image in it's paint() method... you would need to make it create ActionEvents( since that's what buttons create ) when it is clicked on... you would probably do this by making the new class implement MouseListener and KeyListener( to get mouse clicks and key presses on this new class ) and have it draw the new class differently( i.e. different image, border change, something to show it is "pressed" ) and have it create the ActionEvent...
Then you just use this new AWT component in your applet or application.
I know that I was kind of sketchy on the details... please ask if something is not understandable, or if you need an example.
HTH,
-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Rose,
Here is an example of some code to create a button with an image on it... if it meets your needs, great! If not, hopefully it can be modified to do just what you want!

Just use it like a normal Button in your applets or applications!
Email me or post on here if you have any problems with it!
HTH,
-Nate
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to code a button with image
 
Similar Threads
how to upload an image through jsp
Redirecting Servlet
fit the image to the button size
Make only a part of an image button clickable.
How to pass different request Parameters