0

JAVA 如何从可选对话框中获取价值

你好,我需要帮助,因为我在堆栈 =D 时遇到了这个问题,我做了一个小程序,现在我做了一个小选项对话框,里面有几个选项我想保存选项你选择为 Int 我该怎么做,这是代码:

final JButton btnOdaberi = new JButton("Odaberi");
        btnOdaberi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int t = 0;
                String[] rate = {"1","2","3","4","5","6","7","8","9","10","11","12"};
             int izaberi = JOptionPane.showOptionDialog(btnOdaberi, "Izaberi broj rata", "Rate",0,t,null, rate,"1");
    }

提前致谢。

4

1 回答 1

0

您已经将它保存在 izaberi 变量中,您需要做的就是显示它。尝试:

JOptionPane.showMessageDialog(null, "Your choice was: "+(izaberi+1));

在你的 int izaberi 之下...

于 2013-06-02T16:39:19.167 回答