summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/CancelButton.java
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/CancelButton.java')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/CancelButton.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/CancelButton.java b/Master/Reference Architectures and Patterns/hjp5/examples/CancelButton.java
new file mode 100644
index 0000000..8ce77cf
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/hjp5/examples/CancelButton.java
@@ -0,0 +1,29 @@
+/* CancelButton.java */
+
+import java.awt.event.*;
+import javax.swing.*;
+
+public class CancelButton
+extends JButton
+{
+ public CancelButton(String title)
+ {
+ super(title);
+ ActionListener al = new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("PressedESCAPE")) {
+ doClick();
+ }
+ }
+ };
+ registerKeyboardAction(
+ al,
+ "PressedESCAPE",
+ KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
+ JButton.WHEN_IN_FOCUSED_WINDOW
+ );
+ }
+} \ No newline at end of file