import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class Exercice3 
{
	public static void main(String[] args) 
	{
		JFrame jf = new JFrame("Ma super IHM !");
		jf.setSize(300, 300);
		jf.setLayout(new BorderLayout()); // BorderLayout => Crée un style Border
		
		/** Composants **/
		
		JTextField tx = new JTextField(); // Je crée un textfield
		jf.add(tx,BorderLayout.SOUTH); // Je le place en bas de ma fenêtre
		
			// Boutons
		JPanel jp = new JPanel();
		jp.setLayout(new GridLayout(10,10)); 
		for (int i = 0; i < 10; i++) 
		{
			for (int j = 0; j < 10; j++) 
			{
				JButton bouton = new JButton("X"+i+","+j);  // Je crée un bouton nommé Xi,j
				bouton.addActionListener(new MonEcouteur(tx)); // Je lie mon écouteur au bouton
				jp.add(bouton); // J'ajoute le bouton au panel
			}
			
		}
		jf.add(jp,BorderLayout.CENTER); // J'ajoute mon panel à ma frame

		
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);
	}
}

class MonEcouteur implements ActionListener
{
	JTextField tx; // Une référence vers le composant TextField de ma frame
	
	MonEcouteur(JTextField tx)
	{
		this.tx = tx; // Je l'initialise 
	}
	
	public void actionPerformed(ActionEvent e) 
	{
		tx.setText(((JButton)e.getSource()).getText()); // Je modifie le texte du JTextField à la valeur du nom du bouton
		tx.validate(); // Je raffraichi mon composant pour qu'il prenne en compte les dernières modifications
	}
	
}
