// TODO: package import java.awt.Dimension; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class GameWindow extends JFrame implements ActionListener { public static final Dimension WINDOW_SIZE = new Dimension(600, 400); private JPanel menu; // TODO: remove map editor, start directly on Battle mode public GameWindow() { super("Subconscious"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(WINDOW_SIZE); this.setPreferredSize(WINDOW_SIZE); this.setLocationRelativeTo(null); JPanel menu = new JPanel(); menu.setLayout(new GridLayout(3, 1)); JButton editor = new JButton("Editor"); editor.setActionCommand("btn-editor"); JButton battle = new JButton("Battle"); battle.setActionCommand("btn-battle"); JButton exit = new JButton("Exit"); exit.setActionCommand("btn-exit"); editor.addActionListener(this); battle.addActionListener(this); exit.addActionListener(this); menu.add(editor); menu.add(battle); menu.add(exit); this.menu = menu; this.add(this.menu); this.pack(); this.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().startsWith("btn")) { if (e.getActionCommand().equals("btn-exit")) { this.setVisible(false); this.dispose(); return; } Scene scene = null; if (e.getActionCommand().equals("btn-editor")) { scene = new MapEditorScene(); } else if (e.getActionCommand().equals("btn-battle")) { scene = new BattleScene(); } if (scene == null) { return; } this.getContentPane().removeAll(); this.getContentPane().invalidate(); this.getContentPane().add(scene); this.getContentPane().revalidate(); scene.updateCanvasSize(); Thread sceneThread = new Thread(scene); sceneThread.start(); } } public void backToMenu() { this.getContentPane().removeAll(); this.getContentPane().invalidate(); this.getContentPane().add(this.menu); this.getContentPane().revalidate(); } }