You can use AbstractButton#setActionCommand.
In your loop:
buttons[i].setActionCommand(i+"");
Then you'll get i
back when you use getActionCommand
Note I did mention in a comment on another answer that I would create a new class Mine
which extends JButton
which I believe to be a better and more complete solution. This however gets the job done rather quickly.