95 lines
3.2 KiB
Java
95 lines
3.2 KiB
Java
import java.awt.*;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import javax.swing.*;
|
|
|
|
/**
|
|
* Klasse zum Erstellen von MainMenu Objekten
|
|
* Dient als Hauptmenü für die Anwendung
|
|
* @author Lucas Bronson
|
|
*/
|
|
public class MainMenuView extends JPanel {
|
|
|
|
private JLabel titelLabel = new JLabel("Studium versenken");
|
|
private JButton lokalButton = new JButton("Lokal");
|
|
private JButton multiButton = new JButton("Multiplayer");
|
|
private JButton soundButton;
|
|
|
|
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
|
private ImageIcon soundIcon = new ImageIcon("graphics/sound button.png");
|
|
private ImageIcon muteIcon = new ImageIcon("graphics/sound button muted.png");
|
|
|
|
/**
|
|
* Konstruktor der MainMenuView Klasse
|
|
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
|
* @author Lucas Bronson
|
|
*/
|
|
public MainMenuView(MainFrame frame) {
|
|
setLayout(null);
|
|
buildPanel(frame);
|
|
}
|
|
|
|
/**
|
|
* Methode zum Füllen des Panels, Objekte werden dem frame hinzugefügt
|
|
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
|
* @author Lucas Bronson
|
|
*/
|
|
private void buildPanel(MainFrame frame) {
|
|
lokalButton.setBounds(200, 200, 500, 500);
|
|
multiButton.setBounds(800, 200, 500, 500);
|
|
titelLabel.setBounds(550, 10, 700, 100);
|
|
soundButton = new JButton(soundIcon);
|
|
soundButton.setBounds(20, 20, 128, 128);
|
|
|
|
titelLabel.setFont(robotoFont);
|
|
lokalButton.setFont(robotoFont.deriveFont(50f));
|
|
multiButton.setFont(robotoFont.deriveFont(50f));
|
|
|
|
add(titelLabel);
|
|
add(lokalButton);
|
|
add(multiButton);
|
|
add(soundButton);
|
|
|
|
// ActionListener um vom Hauptmenü zum LocalGame Menü zu wechseln
|
|
lokalButton.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
System.out.println("Lokales Spiel ausgewählt.");
|
|
frame.showPanel("LocalGame"); // Panel wechseln
|
|
}
|
|
});
|
|
|
|
// ActionListener um vom Hauptmenü zum MultiPlayerGame Menü zu wechseln
|
|
multiButton.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
System.out.println("Multiplayer-Spiel ausgewählt.");
|
|
frame.showPanel("MultiplayerGame"); // Panel wechseln
|
|
}
|
|
});
|
|
|
|
//Aufruf von toggleMute, falls der soundButton geklickt wird
|
|
soundButton.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
System.out.println("Soundbutton geklickt.");
|
|
toggleMute();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Setzt Sound auf Stumm/Laut und ändert Grafik, sodass
|
|
* der aktuelle Stand der Grafik entspricht
|
|
* @author Lucas Bronson, Joshua Kuklok
|
|
*/
|
|
private void toggleMute() {
|
|
if (soundButton.getIcon() == soundIcon) {
|
|
soundButton.setIcon(muteIcon);
|
|
SoundHandler.setSoundOn(false);
|
|
} else {
|
|
soundButton.setIcon(soundIcon);
|
|
SoundHandler.setSoundOn(true);
|
|
}
|
|
}
|
|
} |