Java Eclipse为什么要创建一个额外的窗口

Java Eclipse为什么要创建一个额外的窗口,java,swing,Java,Swing,我想做一个发射器。它工作得很好,只是当我按下“选项”按钮时,它会在角落里形成一个小窗口。我如何防止这种情况 启动器图片: (来源:) 现在运行选项框: (来源:) 你可以看到角落里的小窗户。当选项帧消失时,它不会消失 主文件: package ca.sidez.Launcher; import javax.swing.*; import javax.swing.border.EmptyBorder; import ca.sidez.Main.Game; import java.awt.*;

我想做一个发射器。它工作得很好,只是当我按下“选项”按钮时,它会在角落里形成一个小窗口。我如何防止这种情况

启动器
图片:
(来源:)

现在运行选项框:
(来源:)

你可以看到角落里的小窗户。当
选项
帧消失时,它不会消失

主文件:

package ca.sidez.Launcher;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import ca.sidez.Main.Game;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

public class Main {

    private Game ga;

    public static int game = 0;
    public static int isUpdate = 0;
    public static int BigVersion = 00;
    public static String Version = "04";
    public static String Potenic_Version = "1.6a";
    public static String DirtLife_Version = "0.1";
    public static int lang = 0;

    private static void createWindow() {

        Font font;
        Font font2;

        final JFrame frame = new JFrame("Nic Launcher " + Version);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(820, 640);
        frame.setLocationRelativeTo(null);
        frame.setLayout(null);
        frame.setResizable(false);

        JEditorPane jep = new JEditorPane();
        jep.setEditable(false);

        font = new Font("Times New Roman", Font.PLAIN, 28);
        font2 = new Font("Arial", Font.BOLD, 14);

        jep.setContentType("text/html");
        jep.setText("<html> Loading... </html>");
        jep.setBorder(new EmptyBorder(0, 0, 0, 0));
        try {
            jep.setPage("http://potenic.tumblr.com/");
        } catch(IOException e) {
            jep.setContentType("text/html");
            jep.setText("<html>Could not load, Check Your Connection</html>");
        }

        JScrollPane scrollPane = new JScrollPane(jep);
        scrollPane.setBackground(Color.BLACK);

        scrollPane.setSize(640, 480);
        scrollPane.setLocation(0, 0);
        scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));

         final JRadioButton potenic = new JRadioButton("Potenic: " + Potenic_Version);
         final JRadioButton Launcher = new JRadioButton("Launcher");

         potenic.setBounds(675, 150, 200, 55);
         Launcher.setBounds(675, 100, 200, 55);

         ButtonGroup bg = new ButtonGroup();
         bg.add(potenic);
         bg.add(Launcher);

         Launcher.setVisible(false);

         ActionListener al = new ActionListener() {
             public void actionPerformed(ActionEvent ae) {
                 if(potenic.isSelected()) {
                     game = 1;
                     Launcher.setVisible(true);
                 } else {
                     game = 0;
                     Launcher.setVisible(false);
                 }
             }
        };
        potenic.addActionListener(al);
        Launcher.addActionListener(al);

        //Enslish

        if(lang == 0) {
选项代码:

package ca.sidez.Launcher;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import ca.sidez.Main.Game;
import ca.sidez.Main.GamePanel;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

public class Working extends JFrame {

private Game ga;

public static int game;

    Font font;
    Font font2;

    public Working() {
    final JFrame frame = new JFrame("Working In Progress");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setLayout(new FlowLayout());
    frame.setResizable(false);

    font = new Font("Times New Roman", Font.PLAIN, 28);
    font2 = new Font("Arial", Font.BOLD, 14);

    JLabel working = new JLabel("Working In Progress");
    frame.add(working);

    //English

    if(Main.lang == 0) {
    JButton launchButton = new JButton("Back");
    launchButton.setBounds(50, 300, 150, 55);
    launchButton.setFont(font);
    launchButton.setVisible(true);

    launchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            frame.dispose();
        }
    });
    frame.add(launchButton);
}

    //Svenska

    if(Main.lang == 1) {
        JButton launchButton = new JButton("Gå Tillbaks");
        launchButton.setBounds(50, 300, 150, 55);
        launchButton.setFont(font);
        launchButton.setVisible(true);

        launchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            }
        });
        frame.add(launchButton);
    }

    //Suomi

    if(Main.lang == 2) {
        JButton launchButton = new JButton("Takaisin");
        launchButton.setBounds(50, 300, 150, 55);
        launchButton.setFont(font);
        launchButton.setVisible(true);

        launchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

            }
        });
        frame.add(launchButton);
    }

    frame.setVisible(true);
}
 }

选项Button.addActionListener
(变量的名称很糟糕,不应该以大写字母开头)中,您创建了一个
工作
对象,它是一个JFrame,并显示出来

但是,在您的
Working
类中(真是个坏名字),它扩展了
JFrame
您的工作并显示了
final JFrame
属性

这就是为什么会出现两个窗口(
JFrame
) 删除
工作
中的
最终JFrame帧
,只需使用

package ca.sidez.Launcher;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import ca.sidez.Main.Game;
import ca.sidez.Main.GamePanel;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

public class Working extends JFrame {

private Game ga;

public static int game;

    Font font;
    Font font2;

    public Working() {
    final JFrame frame = new JFrame("Working In Progress");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setLayout(new FlowLayout());
    frame.setResizable(false);

    font = new Font("Times New Roman", Font.PLAIN, 28);
    font2 = new Font("Arial", Font.BOLD, 14);

    JLabel working = new JLabel("Working In Progress");
    frame.add(working);

    //English

    if(Main.lang == 0) {
    JButton launchButton = new JButton("Back");
    launchButton.setBounds(50, 300, 150, 55);
    launchButton.setFont(font);
    launchButton.setVisible(true);

    launchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            frame.dispose();
        }
    });
    frame.add(launchButton);
}

    //Svenska

    if(Main.lang == 1) {
        JButton launchButton = new JButton("Gå Tillbaks");
        launchButton.setBounds(50, 300, 150, 55);
        launchButton.setFont(font);
        launchButton.setVisible(true);

        launchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            }
        });
        frame.add(launchButton);
    }

    //Suomi

    if(Main.lang == 2) {
        JButton launchButton = new JButton("Takaisin");
        launchButton.setBounds(50, 300, 150, 55);
        launchButton.setFont(font);
        launchButton.setVisible(true);

        launchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

            }
        });
        frame.add(launchButton);
    }

    frame.setVisible(true);
}
 }