View Full Version : Java's Event Handler

07-17-2004, 05:04 AM
I have a general idea how event handlers work in java. My question is if I have two buttons:

JButton buttonOne = new JButton("ADD");
JButton two = new JButton("ADD");

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:

Any help would be nice....

07-18-2004, 01:38 AM
if (e.getSource() == buttonOne ) {
Do Something;

07-18-2004, 09:17 AM

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 !!! :thumbsup: