Create an instance of object to the Buttons..
JButton button1 = new JButton("btn1");
JButton button1 = new JButton("btn1");
then add them to the Panel
btns.add(button1 );
btns.add(button2 );
add the a action command to the Buttons:
button1.setActionCommand("button1");
button2.setActionCommand("button2");\
create a class that implements ActionListener
private class Controller implements ActionListener
In the actionPerformed get the actionCommand and checks it with the correnponding button:
@Override
public void actionPerformed(ActionEvent evt)
{
String actionCommand = evt.getActionCommand(); //get the actionCommand and pass it to String actionCommand
if(actionCommand.equals("button1"))
//button 1 clicked
else if(actionCommand.equals("button2"))
//button 1 clicked
}