Click to See Complete Forum and Search --> : key button help


aj_306
12-06-2005, 05:11 AM
hi all,

jus a simple question, how would i code a button so that if the NUMPAD 0 was pressed, it would change the buttons icon? i am currently using an image for the button and wish to change that image to a different upon select.

thanks

java newbie

sjalle
12-06-2005, 05:45 AM
I assume the problem is the image switching, not catching the Numpad 0 keystroke.

The hard way:
Make a JButton extension (ImageButton ?), introduce a new constructor that has two Images
as parameters. Then override the paintComponent(Graphics g) method in the
JButton. In this method you paint one or the other image, based on a flag that is
set by a method you include in the ImageButton class, say, setImage(boolean onOff). This method is invoked on every Numpad 0 keystroke.

The easy way:

Make your button a JToggleButton, and set the images using the setSelectedIcon and
the setIcon methods. Switch image by invoking the setSelected method for the button.

aj_306
12-06-2005, 06:06 AM
thanks for that mate! i took the asy option lol!!!

on the off chance can u recommend any easy, Zoom, pan and rotate methods / code that i can implement for my buttons? i have zoom code but its very comprehensive!!!

if not its ok thanks for ur help... much appreciated!

sjalle
12-06-2005, 10:11 AM
Check this out

http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html

and here is a sample applet that I made a while back, it zooms and pans, and, well,
its a bit comprehensive, but it doesnt do anything unnecessary...

aj_306
12-06-2005, 10:57 AM
thanks alot sjalle!

i will have a look at the code, i am not getting no image up tho!

mate u have really helped me alot, its very decent of u, thanks! :)

aj_306
12-07-2005, 05:04 AM
i have compiled ur zoom applet but it says that there are "none" image/s to display... where do i enter the image path?

aj_306
12-07-2005, 06:43 AM
hello?

aj_306
12-07-2005, 06:49 AM
i think i may have to start a new topic?