Erstellen von MVC für MultiPlayerMenu, anpassen von Controller und View des MainMenu.
Fensterwechsel eingefügt, bessere Idee wird die Tage implementiert
This commit is contained in:
parent
d95b467f72
commit
5f6d5b426d
|
@ -16,9 +16,11 @@ public class MainMenuController implements ActionListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (e.getSource() == view.getLocalButton()) {
|
if (e.getSource() == view.getMultiButton()) {
|
||||||
model.setGameMode("Local");
|
view.closeWindOw();
|
||||||
JOptionPane.showMessageDialog(view.getFrame(), "Local game selected.");
|
MultiMenuModel model = new MultiMenuModel();
|
||||||
|
MultiMenuView view = new MultiMenuView();
|
||||||
|
MultiMenuController controller2 = new MultiMenuController(model, view);
|
||||||
} else if (e.getSource() == view.getMultiButton()) {
|
} else if (e.getSource() == view.getMultiButton()) {
|
||||||
model.setGameMode("Multiplayer");
|
model.setGameMode("Multiplayer");
|
||||||
JOptionPane.showMessageDialog(view.getFrame(), "Multiplayer game selected.");
|
JOptionPane.showMessageDialog(view.getFrame(), "Multiplayer game selected.");
|
||||||
|
|
|
@ -49,9 +49,11 @@ public class MainMenuView {
|
||||||
}else{
|
}else{
|
||||||
soundButton.setIcon(SoundIcon);
|
soundButton.setIcon(SoundIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void closeWindOw(){
|
||||||
|
frame.dispose();
|
||||||
|
}
|
||||||
public JFrame getFrame() {
|
public JFrame getFrame() {
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class MultiMenuController implements ActionListener {
|
||||||
|
private MultiMenuView view;
|
||||||
|
private MultiMenuModel model;
|
||||||
|
|
||||||
|
public MultiMenuController(MultiMenuModel model, MultiMenuView view) {
|
||||||
|
this.view = view;
|
||||||
|
this.model = model;
|
||||||
|
this.view.getSoundButton().addActionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (e.getSource() == view.getSoundButton()) {
|
||||||
|
view.toggleMute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
public class MultiMenuModel {
|
||||||
|
private String gameMode;
|
||||||
|
|
||||||
|
public void setGameMode(String mode) {
|
||||||
|
this.gameMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGameMode() {
|
||||||
|
return gameMode;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class MultiMenuView {
|
||||||
|
ImageIcon SoundIcon = new ImageIcon("Grafik/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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void buildComponents(){
|
||||||
|
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("Grafik/mainmenubackground.png"));
|
||||||
|
frame.setContentPane(backgroundLabel);
|
||||||
|
frame.add(soundButton);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleMute(){
|
||||||
|
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
|
||||||
|
if(soundButton.getIcon()==SoundIcon) {
|
||||||
|
soundButton.setIcon(MuteIcon);
|
||||||
|
}else{
|
||||||
|
soundButton.setIcon(SoundIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeWindOw(){
|
||||||
|
frame.dispose();
|
||||||
|
}
|
||||||
|
public JFrame getFrame() {
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getSoundButton() {
|
||||||
|
return soundButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue