package avs.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MainFrame extends JFrame {
    private CardLayout cardLayout;
    private Container container;

    public final static int WIDTH = 1280;
    public final static int HEIGHT = 720;

    public MainFrame() {
        super("Acads vs. Students");

        cardLayout = new CardLayout();
        container = this.getContentPane();

        JButton menuButton = new JButton("Main Menu");
        JButton gameButton = new JButton("Start Game");
        JButton settingsButton = new JButton("Settings");


        JPanel buttonPanel = new JPanel(new FlowLayout());

        buttonPanel.add(menuButton);
        buttonPanel.add(gameButton);
        buttonPanel.add(settingsButton);

        JPanel cardPanel = new JPanel(cardLayout);

        cardPanel.add("menu", new MainMenuPanel());
        cardPanel.add("game", new GamePanel());
        cardPanel.add("settings", new SettingsPanel());

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        container.setPreferredSize(
            new Dimension(MainFrame.WIDTH, MainFrame.HEIGHT));
        this.pack();
        this.setLocationRelativeTo(null);

        this.container.setLayout(new BorderLayout());
        this.container.add(buttonPanel, BorderLayout.NORTH);
        this.container.add(cardPanel, BorderLayout.CENTER);

        menuButton.addActionListener(new SwitchPanelAction(cardPanel, "menu"));
        gameButton.addActionListener(new SwitchPanelAction(cardPanel, "game"));
        settingsButton.addActionListener(
            new SwitchPanelAction(cardPanel, "settings")
        );

        this.setVisible(true);
    }

    private class SwitchPanelAction implements ActionListener {
        private Container parent;
        private String tag;

        public SwitchPanelAction(Container parent, String tag) {
            this.parent = parent;
            this.tag = tag;
        }

        public void actionPerformed(ActionEvent e) {
            cardLayout.show(parent, tag);
        }
    }
}

@@ -421,355 +421,8 @@
 );%0A%0A
-        JButton menuButton = new JButton(%22Main Menu%22);%0A        JButton gameButton = new JButton(%22Start Game%22);%0A        JButton settingsButton = new JButton(%22Settings%22);%0A%0A%0A        JPanel buttonPanel = new JPanel(new FlowLayout());%0A%0A        buttonPanel.add(menuButton);%0A        buttonPanel.add(gameButton);%0A        buttonPanel.add(settingsButton);%0A%0A
     
@@ -877,428 +877,21 @@
 ner.
-setLayout(new BorderLayout());%0A        this.container.add(buttonPanel, BorderLayout.NORTH);%0A        this.container.add(cardPanel, BorderLayout.CENTER);%0A%0A        menuButton.addActionListener(new SwitchPanelAction(cardPanel, %22menu%22));%0A        gameButton.addActionListener(new SwitchPanelAction(cardPanel, %22game%22));%0A        settingsButton.addActionListener(%0A            new SwitchPanelAction(cardPanel, %22settings%22)%0A        
+add(cardPanel
 );%0A%0A

Remove button panel.