小编use*_*881的帖子

JOptionPane上的ActionListener

我正在关注如何创建自定义对话框的Oracle教程:http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html

我有两个按钮:Save Object和Delete Object,点击它们时应该执行某段代码.不幸的是,我似乎无法向JOptionPane按钮添加任何ActionListener,因此当它们被点击时没有任何反应.

任何人都可以帮我告诉我如何做到这一点?这是我到目前为止对话框的类:

class InputDialogBox extends JDialog implements ActionListener, PropertyChangeListener {
    private String typedText = null;
    private JTextField textField;

    private JOptionPane optionPane;

    private String btnString1 = "Save Object";
    private String btnString2 = "Delete Object";

    /**
     * Returns null if the typed string was invalid;
     * otherwise, returns the string as the user entered it.
     */
    public String getValidatedText() {
        return typedText;
    }

    /** Creates the reusable dialog. */
    public InputDialogBox(Frame aFrame, int x, int y) …
Run Code Online (Sandbox Code Playgroud)

java swing jdialog joptionpane

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

jdialog ×1

joptionpane ×1

swing ×1