Results 1 to 4 of 4
  1. #1
    Luwine is offline Member
    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0

    Default Listeners help!!

    im building a calculator and i want to press the button, get the text and set it in the text field as a text....but i want to touch any button not one in expecific

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    11

    Default Re: Listeners help!!

    Where is your SSCCE? Note that this shouldn't be your whole program, but it should demonstrate exactly what you're doing.

    Until then, recommended reading: How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    Luwine is offline Member
    Join Date
    Jun 2013
    Posts
    10
    Rep Power
    0

    Default Re: Listeners help!!

    ok if i put this.............textf.setText(button[2].getText());...............it works, but, i want it in all buttons

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,314
    Blog Entries
    7
    Rep Power
    25

    Default Re: Listeners help!!

    Quote Originally Posted by Luwine View Post
    ok if i put this.............textf.setText(button[2].getText());...............it works, but, i want it in all buttons
    Hook up your event handler to all your buttons (and only buttons) so you can safely cast the ae.getSource() value to a JButton. Get the text from that button and do with it as you please.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Key Listeners
    By wired-in=p in forum New To Java
    Replies: 17
    Last Post: 09-17-2011, 08:27 PM
  2. two different Listeners
    By Billaguana in forum New To Java
    Replies: 8
    Last Post: 01-21-2011, 04:20 AM
  3. key listeners
    By zjames in forum New To Java
    Replies: 22
    Last Post: 11-24-2010, 06:58 AM
  4. Help with Listeners
    By Psyclone in forum AWT / Swing
    Replies: 8
    Last Post: 02-09-2010, 08:21 PM
  5. Seriously need help on my listeners!!
    By themburu in forum Java Applets
    Replies: 4
    Last Post: 05-26-2008, 10:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •