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

public class CelluleClique extends JFrame implements MouseListener
{
	private JLabel celluleclic;
	private JTable table;

	public CelluleClique ()
	{
		super ("Demo");

		String [] colonne = { "Premiere", "Deuxieme", "Troiseme", "Quatrieme" };
		Object [][] data = { {"1", "2", "3", "4"}, {"5", "6", "7", "8"}, {"9", "10", "11", "12"} };
		this.table = new JTable (data, colonne);
		this.table.addMouseListener (this);
		this.getContentPane ().add (this.table);
		this.getContentPane ().add (this.table.getTableHeader (), BorderLayout.NORTH);

		this.celluleclic = new JLabel ("   ligne :    colonne :  ");
		this.getContentPane ().add (this.celluleclic, BorderLayout.SOUTH);

		this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		this.setLocation (200, 200);
		this.pack ();
		this.setVisible (true);
	}

	public void mouseClicked (MouseEvent e)
	{
		Point p = e.getPoint ();
		int colonne = this.table.columnAtPoint (p)+1;
		int ligne = this.table.rowAtPoint (p)+1;

		// si la souris n'a pas clic sur une cellule :
		if ( (0 == colonne) || (0 == ligne) )
		{
			this.celluleclic.setText ("   ligne :    colonne :  ");
		}
		else
		{
			this.celluleclic.setText ("   ligne : "+ligne+"  colonne : "+colonne);
		}
	}

	public void mouseExited (MouseEvent e) { }
	public void mousePressed (MouseEvent e) { }
	public void mouseReleased (MouseEvent e) { }
	public void mouseEntered (MouseEvent e) { }

	public static void main (String argv [])
	{
		new CelluleClique ();
	}
}
