JDialog不断重新开放

时间:2016-07-08 04:31:21

标签: java dialog jdialog

所以我有一个JDialog框,只要你想在我正在制作的程序中制作新东西,就会打开它。第一次打开它时,它关闭它时工作正常。但第二次,当你关闭它时,它会重新打开,你必须再次关闭它。如果你第三次打开它,你必须关闭它三次,你可以看到我在哪里。我假设它是我如何展示它,以及我将它设置为可见且不可见的地方,因此这些是我将呈现的代码段,但如果您还需要其他任何内容,请询问。顺便说一句,JDialog框本身就是一个单独的类。提前谢谢。

首先创建对话

private NewPlatformDialog npd = new NewPlatformDialog(frame, "New Platform", this);

打开

else if(source == mouseNewPlatform || source == newPlatform) {
    npd.setVisible(true);
}

关闭它的地方(构造函数中的第一个)

setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
pack();
setVisible(false);

关闭它的按钮

if(source == cancel) setVisible(false);

应用按钮

`
else if(source == add) {
    if(platformSelector.getSelectedIndex() == 0) {
        int x = 0, y = 0, w = 0, h = 0;
        if(xField != null) x = Integer.parseInt(xField.getText());
        if(yField != null) y = Integer.parseInt(yField.getText());
        if(widthField != null) w = Integer.parseInt(widthField.getText());
        if(heightField != null) h = Integer.parseInt(heightField.getText());

        le.platforms.add(new DragablePlatform(x, y, w, h, Platform.NORMAL));
        le.repaint();

        resetFields();
        setVisible(false);
    }
}

虽然我不认为我做错了什么,但我可能会弄错,所以再次感谢您的帮助。

DragablePlatform Class

package resources;

public class DragablePlatform extends Platform {
public DragablePlatform(int x, int y, int w, int h, int type) {
    super(x, y, w, h, type);
}
public DragablePlatform(int x, int y, int w, int h, int type, int horizVerti, int max) {
    super(x, y, w, h, type, horizVerti, max);
}
}

0 个答案:

没有答案