Skip to content

Instantly share code, notes, and snippets.

@andreyuhai
Last active January 6, 2019 03:04
Show Gist options
  • Save andreyuhai/6b92bf2852b5a8acc33c125aa7d8803b to your computer and use it in GitHub Desktop.
Save andreyuhai/6b92bf2852b5a8acc33c125aa7d8803b to your computer and use it in GitHub Desktop.
How to get a button do more than one action in Java
// Just set the action command and test it in the action listener
// Once clicked this button below it pauses the thread, and when clicked once again it notifies thread to resume. Kinda start/stop
pauseButton.addActionListener(e -> {
if (e.getActionCommand().equals("resume")) {
accountCheckerBot.setRunning(true);
pauseButton.setActionCommand("pause");
pauseButton.setText("Pause");
synchronized (accountCheckerBot) {
accountCheckerBot.notify();
}
} else if (e.getActionCommand().equals("pause")) {
pauseButton.setText("Resume");
pauseButton.setActionCommand("resume");
accountCheckerBot.setRunning(false);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment