Created
December 13, 2012 05:02
-
-
Save HybridEidolon/4274145 to your computer and use it in GitHub Desktop.
This file contains 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
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