Last active
January 6, 2019 03:04
-
-
Save andreyuhai/6b92bf2852b5a8acc33c125aa7d8803b to your computer and use it in GitHub Desktop.
How to get a button do more than one action in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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