blob: 8ce77cfc69a35c243c74b1407b142f359d19e0b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
);
}
}
|