Results 1 to 3 of 3
  1. #1
    monir6464 is offline Member
    Join Date
    Mar 2008
    Location
    Bangladesh
    Posts
    5
    Rep Power
    0

    Default Help. It's urgent

    hello friends,
    I'm making a simple game gui. it got 26 buttons for all 26 letters and a label. these are added to a panel which is added to the frame. now for clicking any button i want to change the label.
    Now in the actionPerformed method how can i get the letter user clicked and change the label?
    Again for all buttons i used like
    i.e." buttonA.addActionListener(new LabelListener()); "
    to add the actionlistener.
    so there is only one actionperformed method for all the buttons.
    I'm not posting the code because i think it's scattered and u wouldn't need it.
    please help.
    I've worked hard to come to this point and now i'm stuck.:confused:

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default

    buttonA.addActionListener(new LabelListener()); "
    to add the actionlistener.
    so there is only one actionperformed method
    Lots of code make the main class an ActionListener and use (this) for the arg in the addActionListener(this); method.

    Look at what the ActionEvent object that is passed to the actionPerformed method contains. You can get access to the component that had the action.

    There must be hundreds of coding examples for this if you do a search.

  3. #3
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

Similar Threads

  1. Hi, need some urgent help!
    By jdark in forum New To Java
    Replies: 2
    Last Post: 04-18-2008, 07:50 AM
  2. Help me ...urgent!
    By googgoo in forum New To Java
    Replies: 7
    Last Post: 04-05-2008, 09:46 AM
  3. please help urgent
    By ananas7777 in forum AWT / Swing
    Replies: 2
    Last Post: 12-25-2007, 09:30 AM
  4. NEED urgent help...
    By bezdapez in forum New To Java
    Replies: 7
    Last Post: 11-27-2007, 05:40 PM
  5. Very Urgent
    By Swamipsn in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 02:56 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
  •