如何关闭JDialog并保存设置?

时间:2017-11-26 14:37:16

标签: java swing jdialog

您好我正在制作一个程序,当我从JDialog中选择一些设置然后点击" ok"时遇到问题,这就是设置没有保存但是回来了原始设置。

PS:我不是说英语的人,所以也许你在我上面的文字中发现了一些错误。

图片 enter image description here

class DrawingSettingWindow extends JDialog {


    public DrawingSettingWindow() {

        this.setTitle("Drawing Setting Window");
        this.setSize(550, 550);
        this.setLocationRelativeTo(null);

        this.setModal(true);

        this.setLayout(new GridLayout(4, 1));

        JLabel selectColorText = new JLabel("Select Drawing Color");

        colorsList = new JComboBox(colors);
        JPanel panel1 = new JPanel();
        panel1.add(selectColorText);
        panel1.add(colorsList);
        add(panel1);

        JLabel selectStyleText = new JLabel("Select Drawing Style");
        JPanel panel2 = new JPanel();

        normal = new JRadioButton("Normal");
        normal.setSelected(true);
        filled = new JRadioButton("Filled");
        ButtonGroup bg = new ButtonGroup();

        bg.add(normal);
        bg.add(filled);
        panel2.add(selectStyleText);
        panel2.add(normal);
        panel2.add(filled);
        add(panel2);

        JButton ok = new JButton("OK");

        add(ok);

        ok.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });




        this.pack();
        this.setVisible(true);

    }

0 个答案:

没有答案