JFrame inside another JFrame

后端 未结 5 694
[愿得一人]
[愿得一人] 2020-12-19 10:55

I have a game of chess. I have written 3 classes. 1st if for game. (chessboard, pieces, and so on) And another one is for menu. (buttons like new, open, set time)

Bo

5条回答
  •  离开以前
    2020-12-19 11:16

    I guess that's what you want to do.

    public class OuterFrame extends JFrame {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        OuterFrame outerFrame = new OuterFrame();
                        outerFrame.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        public OuterFrame() {
            JFrame innerFrame = new JFrame();
            innerFrame.setVisible(true);
        }    
    }
    

    You have a MainFrame (OuterFrame), and you create it. But, you create a JFrame inside this MainFrame. That's not a beautiful thing to do, but it's certainly a way of opening a "JFrame inside the other". This will give you two "windows" on the screen. You could create countless JFrames inside the MainFrame.

提交回复
热议问题