diff --git a/src/HalloSchiffeVersenken.java b/src/HalloSchiffeVersenken.java index d7b2210..8422539 100644 --- a/src/HalloSchiffeVersenken.java +++ b/src/HalloSchiffeVersenken.java @@ -1,7 +1,9 @@ public class HalloSchiffeVersenken { public static void main(String[] args) throws InterruptedException { - MainMenu mainMenu = new MainMenu(); + MainMenuModel model = new MainMenuModel(); + MainMenuView view = new MainMenuView(); + MainMenuController controller = new MainMenuController(model, view); System.out.println("HelloSchiffeVersenekn"); diff --git a/src/MainMenu.java b/src/MainMenu.java deleted file mode 100644 index 6be0bd6..0000000 --- a/src/MainMenu.java +++ /dev/null @@ -1,43 +0,0 @@ -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.*; -import javax.swing.JFrame; -import javax.swing.*; - -public class MainMenu implements ActionListener { - JFrame frame = new JFrame(); - JLabel titelLabel = new JLabel("Studium versenken"); - JButton lokalButton = new JButton("Lokal"); - JButton multiButton= new JButton("Multiplayer"); - JButton soundButton = new JButton(); - Font comicSansFont = new Font("Comic Sans MS", Font.BOLD, 45); - - MainMenu(){ - frame.setLayout(null); - lokalButton.setBounds(100,200,500,500); - multiButton.setBounds(800,200,500,500); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setSize(1500,1000); - frame.setVisible(true); - frame.getContentPane().setBackground( Color.decode("#98F5FF")); - - frame.add(titelLabel); - frame.add(lokalButton); - frame.add(multiButton); - frame.setLocationRelativeTo(null); - titelLabel.setBounds(500,10,700,100); - titelLabel.setFont(comicSansFont); - lokalButton.setFont(comicSansFont.deriveFont(50f)); - multiButton.setFont(comicSansFont.deriveFont(50f)); - - } - - @Override - public void actionPerformed(ActionEvent e) { - if(e.getSource() == lokalButton){ - MainMenu nextMenu= new MainMenu(); - } - } -} - diff --git a/src/MainMenuController.java b/src/MainMenuController.java new file mode 100644 index 0000000..7406f8e --- /dev/null +++ b/src/MainMenuController.java @@ -0,0 +1,26 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.*; + +public class MainMenuController implements ActionListener { + private MainMenuView view; + private MainMenuModel model; + + public MainMenuController(MainMenuModel model, MainMenuView view) { + this.view = view; + this.model = model; + this.view.getLocalButton().addActionListener(this); + this.view.getMultiButton().addActionListener(this); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == view.getLocalButton()) { + model.setGameMode("Local"); + JOptionPane.showMessageDialog(view.getFrame(), "Local game selected."); + } else if (e.getSource() == view.getMultiButton()) { + model.setGameMode("Multiplayer"); + JOptionPane.showMessageDialog(view.getFrame(), "Multiplayer game selected."); + } + } +} \ No newline at end of file diff --git a/src/MainMenuModel.java b/src/MainMenuModel.java new file mode 100644 index 0000000..de9a8d4 --- /dev/null +++ b/src/MainMenuModel.java @@ -0,0 +1,11 @@ +public class MainMenuModel { + private String gameMode; + + public void setGameMode(String mode) { + this.gameMode = mode; + } + + public String getGameMode() { + return gameMode; + } +} \ No newline at end of file diff --git a/src/MainMenuView.java b/src/MainMenuView.java new file mode 100644 index 0000000..0b6eea9 --- /dev/null +++ b/src/MainMenuView.java @@ -0,0 +1,52 @@ +import java.awt.*; +import javax.swing.JFrame; +import javax.swing.*; + +public class MainMenuView { + private JFrame frame = new JFrame(); + private JLabel titelLabel = new JLabel("Studium versenken"); + private JButton lokalButton = new JButton("Lokal"); + private JButton multiButton= new JButton("Multiplayer"); + private JButton soundButton = new JButton(); + private ImageIcon background = new ImageIcon("images/background.jpg"); + + Font robotoFont = new Font("Roboto", Font.BOLD, 45); + + public MainMenuView() { + buildFrame(); + buildComponents(); + + } + public void buildComponents(){ + lokalButton.setBounds(200,200,500,500); + multiButton.setBounds(800,200,500,500); + titelLabel.setBounds(550,10,700,100); + titelLabel.setFont(robotoFont); + lokalButton.setFont(robotoFont.deriveFont(50f)); + multiButton.setFont(robotoFont.deriveFont(50f)); + } + + public void buildFrame() { + frame.setLayout(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(1500,1000); + frame.setVisible(true); + frame.getContentPane().setBackground( Color.decode("#98F5FF")); + frame.add(titelLabel); + frame.add(lokalButton); + frame.add(multiButton); + frame.setLocationRelativeTo(null); + } + + public JButton getLocalButton() { + return lokalButton; + } + + public JButton getMultiButton() { + return multiButton; + } + + public JFrame getFrame() { + return frame; + } +}