Simple ActionListener within a 2D array of JButtons

后端 未结 4 1449
不思量自难忘°
不思量自难忘° 2020-12-04 00:56

Okay so I am making a 2d array of JToggleButtons. I got the action listener up and going, but I have no way to tell which button is which.

If I click one, all it ret

4条回答
  •  无人及你
    2020-12-04 01:28

    Instead of 'e.getSource()' you can always call 'e.getActionCommand()'. For each button you can specify this by:

    JButton button = new JButton("Specify your parameters here"); /*you get these from getActionCommand*/
    button.setText("title here"); /*as far as I remember*/
    

提交回复
热议问题