I am trying to add a JButton array that I added to a panel onto my JFrame, yet nothing is showing up

后端 未结 1 561
盖世英雄少女心
盖世英雄少女心 2021-01-25 00:47

Here is my code: For some reason nothing will appear on my screen, yet I don\'t know why, I believe I am initializing it correctly and adding it. Help?

import j         


        
相关标签:
1条回答
  • 2021-01-25 00:54

    Call mainFrame.setVisible(true); last

    private void Start()
    {
    
        JFrame mainFrame = new JFrame("MineSweeper");
        // Move this...
        //mainFrame.setVisible(true);
        //...
        mainFrame.add(p1, BorderLayout.CENTER); 
        // To here
        mainFrame.setVisible(true);
    }
    

    You should also launch you application with the context of the EDT. Take a look at Initial Threads for more details

    You should also avoid using a MouseListener on buttons, they have a ActionListener API which includes notification when the use clicks the button or "active" key (usually Enter or Space)

    0 讨论(0)
提交回复
热议问题