!747 !actionListener { !x619 // CenteredLine m { static S input = ""; static S description = "?"; static boolean ok; static JFrame frame; static JTextField textField; static Runnable onOK, onCancel; p { JButton btnOK = new JButton("OK"); btnOK.addActionListener(actionListener { ok(); }); JButton btnCancel = new JButton("Cancel"); btnCancel.addActionListener(actionListener { cancel(); }); JPanel panel = topToBottomPanel(); textField = new JTextField(input); panel.add(new JLabel(description, JLabel.CENTER)); panel.add(textField); textField.addActionListener(actionListener { ok(); }); panel.add(new CenteredLine(btnOK, btnCancel)); frame = new JFrame("Input | " + description); handleEscapeKey(frame); KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); frame.getRootPane().registerKeyboardAction(actionListener { cancel(); }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); frame.add(panel); frame.setBounds(200, 300, 400, 250); frame.setVisible(true); //exitOnFrameClose(frame); // unless _noExit is set } static void ok() { ok = true; input = textField.getText(); print("OK: " + quote(input)); frame.dispose(); if (onOK != null) onOK.run(); } static void cancel() { if (ok) return; input = textField.getText(); print("Cancel with " + quote(input)); frame.dispose(); if (onCancel != null) onCancel.run(); } }