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 {
//LUCAS CODE
/*
MainMenuModel model = new MainMenuModel();
MainMenuView view = new MainMenuView();
MainMenuController controller = new MainMenuController(model, view);
*/
//System.out.println("HelloSchiffeVersenekn");

View File

@ -17,13 +17,12 @@ public class MainMenuController implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
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");
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()) {
view.toggleMute();
}

View File

@ -3,6 +3,8 @@ import javax.swing.JFrame;
import javax.swing.*;
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");
private JFrame frame = new JFrame();
private JLabel titelLabel = new JLabel("Studium versenken");
@ -13,33 +15,52 @@ public class MainMenuView {
public MainMenuView() {
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);
lokalButton.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() {
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500,1000);
frame.setVisible(true);
frame.getContentPane().setBackground( Color.decode("#98F5FF"));
frame.setSize(1500, 1000);
frame.setLayout(null);
JLabel backgroundLabel = new JLabel(new ImageIcon("graphics/mainmenubackground.png"));
frame.setContentPane(backgroundLabel);
frame.add(titelLabel);
frame.add(lokalButton);
frame.add(multiButton);
frame.add(soundButton);
backgroundLabel.setBounds(0, 0, 1500, 1000);
mainPanel.setBounds(0, 0, 1500, 1000);
mainPanel.setOpaque(true);
frame.setContentPane(new JPanel(null));
frame.getContentPane().add(backgroundLabel);
frame.getContentPane().add(mainPanel);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
@ -53,7 +74,7 @@ public class MainMenuView {
}
public void closeWindow(){
frame.dispose();
frame.setVisible(false);
}
public JFrame getFrame() {
return frame;

View File

@ -3,31 +3,24 @@ import javax.swing.JFrame;
import javax.swing.*;
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");
private JFrame frame = new JFrame();
private JButton soundButton = new JButton(SoundIcon);
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
public MultiMenuView() {
buildFrame();
buildComponents();
buildPanel();
}
public void buildComponents(){
public void buildPanel(){
soundButton.setBounds(20,20,128,128);
}
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"));
JLabel backgroundLabel = new JLabel(new ImageIcon("graphics/mainmenubackground.png"));
frame.setContentPane(backgroundLabel);
frame.add(soundButton);
frame.setLocationRelativeTo(null);
mainPanel.add(multiPanel, "MultiMenu");
soundButton.setFont(robotoFont.deriveFont(50f));
multiPanel.add(soundButton);
}
public void toggleMute(){
@ -38,6 +31,18 @@ public class MultiMenuView {
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(){
frame.dispose();