diff options
author | mafaldo <mafaldo@heavyhammer.home> | 2018-11-18 22:29:05 +0100 |
---|---|---|
committer | mafaldo <mafaldo@heavyhammer.home> | 2018-11-18 22:29:05 +0100 |
commit | e2bcaecea59bdf3a4092efdc4b9624b3f83f6fec (patch) | |
tree | 90e70bb3954173c25e63b65bbc64bd78f8c854be /src/Sub.java | |
download | Subconscious-java-e2bcaecea59bdf3a4092efdc4b9624b3f83f6fec.tar.gz Subconscious-java-e2bcaecea59bdf3a4092efdc4b9624b3f83f6fec.zip |
initial commit
Diffstat (limited to '')
-rw-r--r-- | src/Sub.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/Sub.java b/src/Sub.java new file mode 100644 index 0000000..06e59c2 --- /dev/null +++ b/src/Sub.java @@ -0,0 +1,80 @@ +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 Sub implements ActionListener { + public static final Dimension WINDOW_SIZE = new Dimension(600, 400); + + private JFrame frame; + private JPanel menu; + + public Sub() { + this.frame = new JFrame("Sub"); + + this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.frame.setSize(WINDOW_SIZE); + this.frame.setPreferredSize(WINDOW_SIZE); + this.frame.setLocationRelativeTo(null); + + JPanel menu = new JPanel(); + menu.setLayout(new GridLayout(3, 1)); + JButton editor = new JButton("Editor"); + editor.setActionCommand("editor"); + JButton battle = new JButton("Battle"); + battle.setActionCommand("battle"); + JButton exit = new JButton("Exit"); + exit.setActionCommand("exit"); + + editor.addActionListener(this); + battle.addActionListener(this); + exit.addActionListener(this); + + menu.add(editor); + menu.add(battle); + menu.add(exit); + + this.menu = menu; + + this.frame.add(this.menu); + this.frame.pack(); + + this.frame.setVisible(true); + } + + @Override + public void actionPerformed(ActionEvent e) { + if ("editor".equals(e.getActionCommand())) { + MapEditor test = new MapEditor(frame, this); + this.frame.getContentPane().removeAll(); + this.frame.getContentPane().invalidate(); + this.frame.getContentPane().add(test); + this.frame.getContentPane().revalidate(); + test.start(); + } else if ("battle".equals(e.getActionCommand())) { + Battle test = new Battle(frame, this); + this.frame.getContentPane().removeAll(); + this.frame.getContentPane().invalidate(); + this.frame.getContentPane().add(test); + this.frame.getContentPane().revalidate(); + test.start(); + } else if ("exit".equals(e.getActionCommand())) { + this.frame.setVisible(false); + this.frame.dispose(); + } + } + + public void backToMenu() { + this.frame.getContentPane().removeAll(); + this.frame.getContentPane().invalidate(); + this.frame.getContentPane().add(this.menu); + this.frame.getContentPane().revalidate(); + } + + public static void main(String[] args) { + Sub sub = new Sub(); + } +} |