Add an ActionListener to the button that sets a boolean, and then just check against that boolean.