All pastes #24810 Raw Edit

Chmmr

public java v1 · immutable
#24810 ·published 2005-10-07 05:22 UTC
rendered paste body
import java.awt.BorderLayout;import java.awt.EventQueue;import java.awt.event.ActionEvent;import java.awt.event.KeyEvent;import javax.swing.AbstractAction;import javax.swing.InputMap;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JTextArea;import javax.swing.JWindow;import javax.swing.KeyStroke;public class Test extends JWindow{    private JPanel container;    private JTextArea textArea;    public Test(JFrame owner) {        super(owner);        setLayout(new BorderLayout());        setFocusableWindowState(true);        container = new JPanel();        textArea = new JTextArea("foo bar");        final String key = "exitAction";        final InputMap inputMap =            textArea.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), key);        textArea.getActionMap().put(key, new AbstractAction() {            public void actionPerformed(ActionEvent e) {                System.exit(0);            }        });        container.add(textArea);        getContentPane().add(container, BorderLayout.CENTER);        setSize(400, 400);        setLocationRelativeTo(null);        setVisible(true);    }    public static void main(String[] a) {        EventQueue.invokeLater(new Runnable() {            public void run() {                final JFrame frame = new JFrame("test");                frame.setVisible(true);                new Test(frame);            }        });    }}