You've not given enough information to enable a detailed, specific answer, but you might gain some insight by reviewing
this tutorial that discusses how to program a JButton and other components with ActionListeners using
Java's Swing. The second example on that page sounds a little like what you're describing.
Edit: My answer doesn't seem to corresponds to your topic "Keeping State?" so I apoligize if I've missed your point.