Skip to content

Instantly share code, notes, and snippets.

@wchargin
Created February 24, 2016 15:25
Show Gist options
  • Save wchargin/3726a63c5fd952fe96e2 to your computer and use it in GitHub Desktop.
Save wchargin/3726a63c5fd952fe96e2 to your computer and use it in GitHub Desktop.
// ...
final ActionListener listener = event -> {
if (working) {
return;
}
working = true;
solveButton.setEnabled(false);
solutionArea.setText("Computing solutions\u2026");
progress.setIndeterminate(true);
new SwingWorker<List<Map<Character, Integer>>, Void>() {
@Override
protected List<Map<Character, Integer>> doInBackground()
throws Exception {
return solver.solve(input.getText());
}
@Override
protected void done() {
try {
final List<Map<Character, Integer>> solutions = this
.get();
solutionArea.setText(stringify(solutions));
} catch (InterruptedException e) {
// Cancelled (somehow). Nothing to do.
e.printStackTrace();
} catch (ExecutionException e) {
solutionArea
.setText("Bad input: " + e.getMessage());
} finally {
working = false;
solveButton.setEnabled(true);
progress.setIndeterminate(false);
}
}
}.execute();
};
solveButton.addActionListener(listener);
input.addActionListener(listener);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment