ole #7

Merged
lgc merged 23 commits from ole into main 2024-11-26 14:01:01 +00:00
4 changed files with 64 additions and 40 deletions
Showing only changes of commit a11885c76d - Show all commits

View File

@ -2,11 +2,10 @@ public class HalloSchiffeVersenken {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
//LUCAS CODE //LUCAS CODE
/*
MainMenuModel model = new MainMenuModel(); MainMenuModel model = new MainMenuModel();
MainMenuView view = new MainMenuView(); MainMenuView view = new MainMenuView();
MainMenuController controller = new MainMenuController(model, view); MainMenuController controller = new MainMenuController(model, view);
*/
//System.out.println("HelloSchiffeVersenekn"); //System.out.println("HelloSchiffeVersenekn");

View File

@ -17,13 +17,12 @@ public class MainMenuController implements ActionListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getSource() == view.getMultiButton()) { if (e.getSource() == view.getMultiButton()) {
view.closeWindow();
MultiMenuModel model = new MultiMenuModel();
MultiMenuView view = new MultiMenuView();
MultiMenuController controller2 = new MultiMenuController(model, view);
} else if (e.getSource() == view.getMultiButton()) {
model.setGameMode("Multiplayer"); model.setGameMode("Multiplayer");
JOptionPane.showMessageDialog(view.getFrame(), "Multiplayer game selected."); MultiMenuModel multiModel = new MultiMenuModel();
MultiMenuView multiView = new MultiMenuView();
MultiMenuController multiMenuController = new MultiMenuController(multiModel, multiView);
view.addPanel(multiView.getPanel(), "MultiMenu");
view.showPanel("MultiMenu");
}else if (e.getSource() == view.getSoundButton()) { }else if (e.getSource() == view.getSoundButton()) {
view.toggleMute(); view.toggleMute();
} }

View File

@ -3,6 +3,8 @@ import javax.swing.JFrame;
import javax.swing.*; import javax.swing.*;
public class MainMenuView { public class MainMenuView {
private JPanel mainPanel = new JPanel(new CardLayout()); // CardLayout for switching
private JPanel menuPanel = new JPanel(null);
ImageIcon SoundIcon = new ImageIcon("graphics/sound button.png"); ImageIcon SoundIcon = new ImageIcon("graphics/sound button.png");
private JFrame frame = new JFrame(); private JFrame frame = new JFrame();
private JLabel titelLabel = new JLabel("Studium versenken"); private JLabel titelLabel = new JLabel("Studium versenken");
@ -13,33 +15,52 @@ public class MainMenuView {
public MainMenuView() { public MainMenuView() {
buildFrame(); buildFrame();
buildComponents(); buildPanel();
} }
public void buildPanel(){
mainPanel.add(menuPanel, "MainMenu");
lokalButton.setBounds(200, 200, 500, 500);
multiButton.setBounds(800, 200, 500, 500);
titelLabel.setBounds(550, 10, 700, 100);
soundButton.setBounds(20, 20, 128, 128);
public void buildComponents(){
lokalButton.setBounds(200,200,500,500);
multiButton.setBounds(800,200,500,500);
titelLabel.setBounds(550,10,700,100);
soundButton.setBounds(20,20,128,128);
titelLabel.setFont(robotoFont); titelLabel.setFont(robotoFont);
lokalButton.setFont(robotoFont.deriveFont(50f)); lokalButton.setFont(robotoFont.deriveFont(50f));
multiButton.setFont(robotoFont.deriveFont(50f)); multiButton.setFont(robotoFont.deriveFont(50f));
menuPanel.add(titelLabel);
menuPanel.add(lokalButton);
menuPanel.add(multiButton);
menuPanel.add(soundButton);
// mainPanel.add(menuPanel, "MainMenu");
}
public void showPanel(String panelName) {
CardLayout cl = (CardLayout)mainPanel.getLayout();
cl.show(mainPanel, panelName);
}
public void addPanel(JPanel panel, String name) {
mainPanel.add(panel, name); // Neue Panels hinzufuegen
} }
public void buildFrame() { public void buildFrame() {
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500,1000); frame.setSize(1500, 1000);
frame.setVisible(true); frame.setLayout(null);
frame.getContentPane().setBackground( Color.decode("#98F5FF"));
JLabel backgroundLabel = new JLabel(new ImageIcon("graphics/mainmenubackground.png")); JLabel backgroundLabel = new JLabel(new ImageIcon("graphics/mainmenubackground.png"));
frame.setContentPane(backgroundLabel); backgroundLabel.setBounds(0, 0, 1500, 1000);
frame.add(titelLabel); mainPanel.setBounds(0, 0, 1500, 1000);
frame.add(lokalButton); mainPanel.setOpaque(true);
frame.add(multiButton);
frame.add(soundButton); frame.setContentPane(new JPanel(null));
frame.getContentPane().add(backgroundLabel);
frame.getContentPane().add(mainPanel);
frame.setVisible(true);
frame.setLocationRelativeTo(null); frame.setLocationRelativeTo(null);
} }
@ -53,7 +74,7 @@ public class MainMenuView {
} }
public void closeWindow(){ public void closeWindow(){
frame.dispose(); frame.setVisible(false);
} }
public JFrame getFrame() { public JFrame getFrame() {
return frame; return frame;

View File

@ -3,31 +3,24 @@ import javax.swing.JFrame;
import javax.swing.*; import javax.swing.*;
public class MultiMenuView { public class MultiMenuView {
private JPanel mainPanel = new JPanel(new CardLayout()); // CardLayout for switching
private JPanel multiPanel = new JPanel(null);
ImageIcon SoundIcon = new ImageIcon("graphics/sound button.png"); ImageIcon SoundIcon = new ImageIcon("graphics/sound button.png");
private JFrame frame = new JFrame(); private JFrame frame = new JFrame();
private JButton soundButton = new JButton(SoundIcon); private JButton soundButton = new JButton(SoundIcon);
Font robotoFont = new Font("Roboto", Font.BOLD, 45); Font robotoFont = new Font("Roboto", Font.BOLD, 45);
public MultiMenuView() { public MultiMenuView() {
buildFrame(); buildPanel();
buildComponents();
} }
public void buildComponents(){ public void buildPanel(){
soundButton.setBounds(20,20,128,128); soundButton.setBounds(20,20,128,128);
}
public void buildFrame() { mainPanel.add(multiPanel, "MultiMenu");
frame.setLayout(null); soundButton.setFont(robotoFont.deriveFont(50f));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500,1000); multiPanel.add(soundButton);
frame.setVisible(true);
frame.getContentPane().setBackground( Color.decode("#98F5FF"));
JLabel backgroundLabel = new JLabel(new ImageIcon("graphics/mainmenubackground.png"));
frame.setContentPane(backgroundLabel);
frame.add(soundButton);
frame.setLocationRelativeTo(null);
} }
public void toggleMute(){ public void toggleMute(){
@ -38,6 +31,18 @@ public class MultiMenuView {
soundButton.setIcon(SoundIcon); soundButton.setIcon(SoundIcon);
} }
} }
public JPanel getPanel() {
return multiPanel;
}
public void showPanel(String panelName) {
CardLayout cl = (CardLayout)mainPanel.getLayout();
cl.show(multiPanel, panelName);
}
public void addPanel(JPanel panel, String name) {
multiPanel.add(panel, name);
}
public void closeWindOw(){ public void closeWindOw(){
frame.dispose(); frame.dispose();