Program Idea
Program Idea

Reputation: 101

Change panel display using inside same window

enter image description here enter image description here

Try to make start game after click "Start".

How can I start game inside same window?

public class Object extends JFrame {
    public Object() {
        setLayout(new FlowLayout());
        add(new Main());
        // add(new Board());
        pack();
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setMinimumSize(new Dimension(getWidth(), getHeight()));
        setVisible(true);
    }

    public static void main(String[] args) {
        new Object();
    }
}

Upvotes: 0

Views: 71

Answers (1)

camickr
camickr

Reputation: 324197

Use a CardLayout. You can swap panels when you click the button.

Read the section from the Swing tutorial on How to Use CardLayout for more information and working examples.

Upvotes: 3

Related Questions