Skip to content

Instantly share code, notes, and snippets.

@HybridEidolon
Created December 13, 2012 05:02
Show Gist options
  • Save HybridEidolon/4274145 to your computer and use it in GitHub Desktop.
Save HybridEidolon/4274145 to your computer and use it in GitHub Desktop.
public class CalculatorWindow extends JFrame {
// ...
JButton button0;
JButton button1;
// ...
public void doWhateverSetup() {
// ...
button0.addActionListener(new KeypadButtonAction(0, this));
button1.addActionListener(new KeypadButtonAction(1, this));
// ...
}
// ...
}
class KeypadButtonAction implements ActionListener {
// I can't remember the specific declaration details of ActionListener
// look them up
private int value;
private CalculatorWindow window;
public KeypadButtonAction(int value, CalculatorWindow window) {
this.value = value;
this.window = window;
}
public void onAction(...) {
window.editBox.append(value + "");
// or whatever you want here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment