Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Clicked Button

Status
Not open for further replies.

fatcodeguy

Programmer
Feb 25, 2002
281
CA
Hi... how can I tell if a button has been clicked??
Thanks, Appreciate any help

 
Your class with the buttons will have to implement ActionListener and import java.awt.event.*

Then, for each button that you want to detect clicks on you have add an action listener:
eg: myButton.addActionListener(this);

Then write a method like this (this will get called whenever a button is clicked):

public void actionPerformed(ActionEvent e)
{
Object src = e.getSource();
if (src == myButton)
{
// then myButton has been clicked
}
else if (scr == myOtherButton)
{
// you get the idea...
}
}

Hope this helps

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top