Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java's Event Handler

    I have a general idea how event handlers work in java. My question is if I have two buttons:

    JButton buttonOne = new JButton("ADD");
    buttonOne.addActionListener(this);
    JButton two = new JButton("ADD");
    buttonTwo.addActionListener(this);

    How do I make it so that the add button associates with buttonOne does one thing and the add button associates with buttonTwo does another thing?

    I have tried the following but both buttons does the same thing when I click on it:
    ......e.getActionCommand().equals("ADD");

    Any help would be nice....

  • #2
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if (e.getSource() == buttonOne ) {
    Do Something;
    }

  • #3
    New Coder
    Join Date
    Jun 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool reply



    Hey thats quiet funny, You want the button 2 to perform other function other than the function performed by button, and ur not sure what function you want to perform i guess?, because you have even labeled the caption of your button 2 same as button 1 ie "ADD". and want to perform another function.

    That has to do nothing with the caption, i know that, but first make final what function the button needs to perform then code the statements and then finally give a Condition, which you have given, with not the caption of the buttons but the variables assigned for the buttons. This might work.

    HAPPY PROGRAMMING !!!


  •  

    Posting Permissions

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