hi, i'm new in java, maybe you can try this? in actionPerformed method, do if(e.getSource() == button1){do something} else if(e.getSource() == button2 {do something else} else if .....
Hi. This example is from sun.java Swing tutorial: Detecting User Selections The following code snippet shows how to detect when the user selects a table row. By default, a table allows the user to select multiple rows � not columns or individual cells � and the selected rows need not be next to each other. Using the setSelectionMode method, the following code specifies that only one row at a time can be selected. table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ... //Ask to be notified of selection changes. ListSelectionModel rowSM = table.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { //Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel)e.getSource(); if (lsm.isSelectionEmpty()) { ...//no rows are selected } else { int selectedRow = lsm.getMinSelectionIndex(); ...//selectedRow is selected } } });