簡體   English   中英

為什么我的GUI不顯示?

[英]Why isn't my GUI displaying?

我正在使用inteliJ編寫文件傳輸程序,並且現在正在使用Swing在GUI上工作。 我已經制作了很多程序,但是由於某些原因,我無法弄清為什么我在運行該程序時沒有顯示GUI。 一切都可以編譯。

    public class stage  {

    JPanel mainContainer = new JPanel();
    JPanel window = new JPanel();
    JButton loadButton = new JButton();
    JButton saveButton = new JButton();
    JTextPane cmdOut = new JTextPane();
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu();
    JMenuItem exitButton = new JMenuItem("exit");

public void display(){
    mainContainer.setVisible(true);
    mainContainer.add(window);
    mainContainer.add(menuBar);
    menuBar.add(menu);
    menu.add(exitButton);
    window.setLayout(new GridBagLayout());
    window.add(loadButton);
    window.add(saveButton);
    window.add(cmdOut);
    cmdOut.setText("TEST");
    window.setVisible(true);



}


}

這是我在另一堂課中的主要方法。

public static void main(String[] args) throws IOException {
    stage stage = new stage();

    stage.display();




}

為什么不將主面板放入JFrame中,以便JFrame包含主面板,而主面板容納其他所有內容呢?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM