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

时间:2014-08-12 14:48:24

标签: java swing

我试图制作一个发射器。它工作正常,除了当我按下选项'按钮它在角落里有一个小窗口。我该如何防止这种情况?

Launcher图片:x http://gyazo.com/ab84e162d17b3fba3f9a9d3888c732e7.png

现在选项框架正在运行:y http://gyazo.com/c16c5370d9411c51f0bf732be6f0563e.png

你可以看到角落里的小窗口。当Option框架出现时,它不会消失。

主文件:

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) {

JButton launchButton = new JButton(&#34; Play&#34;);             launchButton.setBounds(50,530,150,55);             launchButton.setFont(字体);             launchButton.setVisible(真);

        launchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(game == 1) {
                    Game.main(null);
                    frame.dispose();
                }
            }
        });
        frame.add(launchButton);

        if(isUpdate == 0) {
            JButton updateButton = new JButton("Check Update");         
            updateButton.setBounds(250, 530, 250, 55);
            updateButton.setFont(font);
            updateButton.setVisible(true);

            updateButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    CheckUpdate frame2 = new CheckUpdate();
                    frame2.setVisible(true);
                    frame.dispose();
                }
            });
            frame.add(updateButton);
        }
        else if(isUpdate == 1) {
            JButton updateButton = new JButton("Update");           
            updateButton.setBounds(250, 530, 150, 55);
            updateButton.setFont(font);
            updateButton.setVisible(true);

            updateButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Downloader frame2 = new Downloader();
                    frame2.setVisible(true);
                    frame.dispose();
                }
            });         
            frame.add(updateButton);
        }

        JButton OptionsButton = new JButton("Options");         
        OptionsButton.setBounds(550, 530, 150, 55);
        OptionsButton.setFont(font);
        OptionsButton.setVisible(true);

        OptionsButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(game == 1) {
                    PotenicOptions frame4 = new PotenicOptions();
                    frame4.setVisible(true);
                    frame.dispose();
                }

                if(game == 0) {
                    Working frame3 = new Working();
                    frame3.setVisible(true);
                    frame.dispose();
                }
            }
        });
        frame.add(OptionsButton);
    }

    //Svenska

    if(lang == 1) {
        JButton launchButton = new JButton("Spela");
        launchButton.setBounds(30, 530, 150, 55);
        launchButton.setFont(font);
        launchButton.setVisible(true);

        launchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(game == 1) {
                    Game.main(null);
                    frame.dispose();
                }
            }
        });
        frame.add(launchButton);

        if(isUpdate == 0) {
            JButton updateButton = new JButton("Titta Efter Uppdateringar");            
            updateButton.setBounds(215, 530, 350, 55);
            updateButton.setFont(font);
            updateButton.setVisible(true);

            updateButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    CheckUpdate frame2 = new CheckUpdate();
                    frame2.setVisible(true);
                    frame.dispose();
                }
            });
            frame.add(updateButton);
        }
        else if(isUpdate == 1) {
            JButton updateButton = new JButton("Uppdatera");            
            updateButton.setBounds(250, 530, 150, 55);
            updateButton.setFont(font);
            updateButton.setVisible(true);

            updateButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Downloader frame2 = new Downloader();
                    frame2.setVisible(true);
                    frame.dispose();
                }
            });         
            frame.add(updateButton);
        }

        JButton OptionsButton = new JButton("Inställningar");           
        OptionsButton.setBounds(600, 530, 200, 55);
        OptionsButton.setFont(font);
        OptionsButton.setVisible(true);

        OptionsButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(game == 1) {
                    PotenicOptions frame4 = new PotenicOptions();
                    frame4.setVisible(true);
                    frame.dispose();
                }

                if(game == 0) {
                LauncherOptions frame3 = new LauncherOptions();
                frame3.setVisible(true);
                frame.dispose();
                }
            }
        });
        frame.add(OptionsButton);
    }

    //Suomi

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

        launchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(game == 1) {
                    Game.main(null);
                    frame.dispose();
                }
            }
        });
        frame.add(launchButton);

        if(isUpdate == 0) {
            JButton updateButton = new JButton("Tarkista päivitys");            
            updateButton.setBounds(250, 530, 250, 55);
            updateButton.setFont(font);
            updateButton.setVisible(true);

            updateButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    CheckUpdate frame2 = new CheckUpdate();
                    frame2.setVisible(true);
                    frame.dispose();
                }
            });
            frame.add(updateButton);
        }
        else if(isUpdate == 1) {
            JButton updateButton = new JButton("päivittää");            
            updateButton.setBounds(250, 530, 150, 55);
            updateButton.setFont(font);
            updateButton.setVisible(true);

            updateButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Downloader frame2 = new Downloader();
                    frame2.setVisible(true);
                    frame.dispose();
                }
            });         
            frame.add(updateButton);
        }

        JButton OptionsButton = new JButton("Asetukset");           
        OptionsButton.setBounds(550, 530, 150, 55);
        OptionsButton.setFont(font);
        OptionsButton.setVisible(true);

        OptionsButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(game == 1) {
                    PotenicOptions frame4 = new PotenicOptions();
                    frame4.setVisible(true);
                    frame.dispose();
                }

                if(game == 0) {
                LauncherOptions frame3 = new LauncherOptions();
                frame3.setVisible(true);
                frame.dispose();
                }
            }
        });
        frame.add(OptionsButton);
    }       
    frame.add(scrollPane);
    frame.add(potenic);
    frame.add(Launcher);
    frame.setVisible(true);
}
public static void main(String[] args) {
    new LoadLang();
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            createWindow();
        }
    });
}
 }

选项代码:

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);
}
 }

1 个答案:

答案 0 :(得分:1)

在你的OptionsButton.addActionListener(变量的名字不是很糟糕,不应该以大写字母开头)中,你创建了一个{J}的Working对象,它出现了。

但是,在您的Working课程(真正糟糕的名字)中,您延伸JFrame工作并显示final JFrame frame属性。

这就是出现两个窗口(JFrame)的原因 删除final JFrame frame中的Working,然后使用this

相关问题