key button help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: key button help

  1. #1
    Join Date
    Nov 2005
    Posts
    24

    key button help

    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

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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.
    eschew obfuscation

  3. #3
    Join Date
    Nov 2005
    Posts
    24
    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!

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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...
    Attached Files Attached Files
    eschew obfuscation

  5. #5
    Join Date
    Nov 2005
    Posts
    24
    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!

  6. #6
    Join Date
    Nov 2005
    Posts
    24
    i have compiled ur zoom applet but it says that there are "none" image/s to display... where do i enter the image path?

  7. #7
    Join Date
    Nov 2005
    Posts
    24
    hello?

  8. #8
    Join Date
    Nov 2005
    Posts
    24
    i think i may have to start a new topic?

Similar Threads

  1. Replies: 7
    Last Post: 07-17-2013, 12:47 AM
  2. button listener not working
    By DrunkinP in forum Java
    Replies: 0
    Last Post: 03-31-2005, 10:36 AM
  3. Replies: 0
    Last Post: 12-09-2002, 12:19 PM
  4. holding a key down and clicking a button with api
    By Shaun Springer in forum VB Classic
    Replies: 14
    Last Post: 06-14-2001, 07:29 PM
  5. holding a key down and clicking a button with api
    By Shaun Springer in forum VB Classic
    Replies: 0
    Last Post: 06-07-2001, 05:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center