import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class buton1 implements ActionListener{
	
	@Override
	public void actionPerformed(ActionEvent arg)
	{
		Calistir.jlb.setText("buton1");	
	}
}
class buton2  implements ActionListener{
   
	@Override
	public void actionPerformed(ActionEvent arg)
	{
		Calistir.jlb.setText("buton2");
	}
}
public class Calistir implements ActionListener {
  static JLabel jlb=new JLabel("----");
  JButton[] jbtn=new JButton[2];
  
	public Calistir()
	{
		JFrame frm=new JFrame("Form");
		frm.setSize(300,300);
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frm.setLayout(new FlowLayout());
		
		jlb.setPreferredSize(new Dimension(100,25));
	    JPanel jpn=new JPanel();
	   jpn.setPreferredSize(new Dimension(100,100));
	  
	   for(int i=0;i<jbtn.length;i++)
	   {
		   jbtn[i]=new JButton("Buton"+(i+1));
		   jbtn[i].setPreferredSize(new Dimension(100,25)); 
	       jpn.add(jbtn[i]);
	   }
	  // jbtn[0].addActionListener(new buton1());// buton1 sınıfındaki actionPerformed fonksiyonun cağır
	   //jbtn[1].addActionListener(new buton2());// buton2 sınıfındaki actionPerformed fonksiyonun cağır
	   jbtn[0].addActionListener(this);//Bu sınıfta ki actionPerformed fonksiyonun cağır
	   jbtn[1].addActionListener(this);//Bu sınıfta ki actionPerformed fonksiyonun cağır
	   jbtn[0].setActionCommand("btn1");
	   jbtn[1].setActionCommand("btn2");
	   jpn.add(jlb);
	   frm.add(jpn);
	   frm.setVisible(true);
	}
	@Override
	public void actionPerformed(ActionEvent arg)
	{
		switch(arg.getActionCommand())
		{
		case "btn1":jlb.setText("buton1");break;
		case "btn2":jlb.setText("buton2");break;
		}
		
	}
	public static void main(String[] arg)
	{
		new Calistir();
	}
}