未显示 JFrame 组件

问题描述

我正在尝试向 JFrame 添加组件,但是当我运行 GameMenu.java 时,唯一显示的是我的 ImageIcon。我已经实例化了setVisible();,特别是之后我已经设置了我的框架或向面板或菜单添加了组件。所以我不确定为什么没有组件出现。我认为这可能与我的格式或主要方法有关。

这是我的两个类:

GameMenu.java:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class GameMenu{

    public static void main(String[] args) {
        FrameCaller obj = new FrameCaller();
    }

}

class FrameCaller extends JFrame {

    public FrameCaller(){
        setLayout(new FlowLayout());
        setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);
        add(new JLabel(new ImageIcon("logo.png")));
        pack();
        setLocationRelativeto(null);

        JMenuBar mb = new JMenuBar();
            JMenu m1 = new JMenu("Game List");
            JMenu m2 = new JMenu("Help");
            JMenu m3 = new JMenu("Stats");
                mb.add(m1);
                mb.add(m2);
                mb.add(m3);
        JMenuItem showRulesButton = new JMenuItem("View game rules");
        m2.add(showRulesButton);
        JMenuItem m77 = new JMenuItem("View past game stats");
        m3.add(m77);
        mb.setVisible(true);

        JPanel panel = new JPanel();
            JButton newGameButton = new JButton("New Game");
            newGameButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    new inGameFrame();
                    dispose();
                }
            });
        panel.add(newGameButton);

        panel.setVisible(true);
        setVisible(true);

    }




}

EightOff.java:

import javax.swing.*;



public class EightOff {

    public static void main(String[] args)
    {
        inGameFrame obj = new inGameFrame();
    }
}

    class inGameFrame extends JFrame
    {
        public inGameFrame() {
            setLayout(new FlowLayout());
            setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);
            pack();
            setLocationRelativeto(null);
            setVisible(true);

        }


    }

任何提示都会很棒。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)