Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用WindowBuilder创建多个JFrame_Java_Eclipse_Swing_Windowbuilder - Fatal编程技术网

Java 使用WindowBuilder创建多个JFrame

Java 使用WindowBuilder创建多个JFrame,java,eclipse,swing,windowbuilder,Java,Eclipse,Swing,Windowbuilder,您好,我想问一下如何在同一个类中编辑WindowBuilder中的多个JFrames。当我用WindowBuilder打开这个类时,它只打开frame1。如何在不创建其他类的情况下编辑frame2 import javax.swing.*; public class Test { public Test(){ openFrames(); } public void openFrames(){ JFrame frame1 = new J

您好,我想问一下如何在同一个类中编辑WindowBuilder中的多个JFrames。当我用WindowBuilder打开这个类时,它只打开frame1。如何在不创建其他类的情况下编辑frame2

import javax.swing.*;

public class Test {

    public Test(){
        openFrames();
    }

    public void openFrames(){
        JFrame frame1 = new JFrame();
        JFrame frame2 = new JFrame();

        frame1.setSize(300, 300);
        frame2.setSize(400, 400);

        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame1.setVisible(true);
        frame2.setVisible(true);
    }

}

顺便说一句,该代码将打开两个帧,但正好在另一个帧之上。此外,如果关闭一个,则两个都将关闭。我建议看一下&如中所示,如果你绝对必须有两个或更多的帧(但我真的怀疑)。@AndrewThompson:我打赌这段代码不是用WindowBuilder创建的。我打赌它会创建扩展JFrame的类。当然,我同意你第一个链接的观点,但我对OP的问题是,如果你必须有多个窗口(而你没有),为什么要将代码合并到一个类中?对于对话框,使用而不是
JFrames
。可以将这些设置为父窗口的临时设置,以便它们保持在父窗口之上(并且通常对系统的行为是正确的)。您仍然没有解释为什么不愿意将代码放在单独的类中。这是您问题中更相关的部分,超出了JFrame/JDialog辩论的范围。