Implemented CardLayout into startMultiplayerGame, startLocalGame, MainMenuView. Implemented MainFrame.
This commit is contained in:
parent
8069315c15
commit
6ef3b38dd5
|
@ -20,10 +20,12 @@ public class MainFrame extends JFrame {
|
||||||
MainMenuView mainMenuView = new MainMenuView(this);
|
MainMenuView mainMenuView = new MainMenuView(this);
|
||||||
startLocalGame localGame = new startLocalGame(this);
|
startLocalGame localGame = new startLocalGame(this);
|
||||||
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
|
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
|
||||||
|
coinToss coinToss = new coinToss(this);
|
||||||
|
|
||||||
mainPanel.add(mainMenuView, "MainMenu");
|
mainPanel.add(mainMenuView, "MainMenu");
|
||||||
mainPanel.add(localGame, "LocalGame");
|
mainPanel.add(localGame, "LocalGame");
|
||||||
mainPanel.add(multiplayerGame, "MultiplayerGame");
|
mainPanel.add(multiplayerGame, "MultiplayerGame");
|
||||||
|
mainPanel.add(coinToss, "coinToss");
|
||||||
|
|
||||||
// Hauptpanel in JFrame hinzufügen
|
// Hauptpanel in JFrame hinzufügen
|
||||||
add(mainPanel);
|
add(mainPanel);
|
||||||
|
|
|
@ -3,36 +3,26 @@ import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class coinToss {
|
public class coinToss extends JPanel {
|
||||||
// Frame
|
// Funktionshilfen
|
||||||
private JFrame frame = new JFrame("Zugreihenfolge");
|
|
||||||
private JPanel mainPanel = new JPanel(new CardLayout()); // Panel mit CardLayout für Szenenwechsel
|
|
||||||
private JLabel frameTitle = new JLabel("Zugreihenfolge", SwingConstants.CENTER);
|
private JLabel frameTitle = new JLabel("Zugreihenfolge", SwingConstants.CENTER);
|
||||||
private JLabel messageLabel = new JLabel("", SwingConstants.CENTER); // Label für die Nachricht
|
private JLabel text = new JLabel("", SwingConstants.CENTER); // Label für die Nachricht
|
||||||
private int reihenfolge = 1; // Beispielhaft: 1 = Spieler 1 fängt an, 0 = Spieler 2 fängt an
|
private int reihenfolge = 1; // Beispielhaft: 1 = Spieler 1 fängt an, 0 = Spieler 2 fängt an
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
|
||||||
coinToss() {
|
// Konstruktor
|
||||||
// Erstelle Frame
|
coinToss(MainFrame frame) {
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setLayout(null); // Setze das Layout des Panels auf CardLayout
|
||||||
frame.setSize(1500, 1000);
|
|
||||||
frame.setLocationRelativeTo(null);
|
|
||||||
|
|
||||||
// Panel für die Startszene erstellen
|
|
||||||
JPanel startPanel = new JPanel();
|
|
||||||
startPanel.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
// Nachricht basierend auf 'reihenfolge' einstellen
|
// Nachricht basierend auf 'reihenfolge' einstellen
|
||||||
String startMessage = (reihenfolge == 1)
|
String startMessage = (reihenfolge == 1)
|
||||||
? "Du fängst an, mach dich bereit..."
|
? "Du fängst an, mach dich bereit..."
|
||||||
: "Dein Gegner fängt an, mach dich bereit...";
|
: "Dein Gegner fängt an, mach dich bereit...";
|
||||||
messageLabel.setText(startMessage);
|
text.setText(startMessage);
|
||||||
messageLabel.setFont(new Font("Arial", Font.BOLD, 24));
|
text.setFont(new Font("Arial", Font.BOLD, 24));
|
||||||
startPanel.add(frameTitle, BorderLayout.NORTH);
|
add(text);
|
||||||
startPanel.add(messageLabel, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
// Panel zur Haupt-Panel hinzufügen
|
frameTitle.setFont(new Font("Arial", Font.BOLD, 32));
|
||||||
mainPanel.add(startPanel, "start");
|
|
||||||
|
|
||||||
// Beispielhaftes "Spielfeld" (nächste Szene)
|
// Beispielhaftes "Spielfeld" (nächste Szene)
|
||||||
JPanel gamePanel = new JPanel();
|
JPanel gamePanel = new JPanel();
|
||||||
|
@ -41,12 +31,8 @@ public class coinToss {
|
||||||
gameLabel.setFont(new Font("Arial", Font.BOLD, 36));
|
gameLabel.setFont(new Font("Arial", Font.BOLD, 36));
|
||||||
gamePanel.add(gameLabel, BorderLayout.CENTER);
|
gamePanel.add(gameLabel, BorderLayout.CENTER);
|
||||||
|
|
||||||
// GamePanel zu Haupt-Panel hinzufügen
|
// Füge das Spiel-Panel zu diesem Panel hinzu
|
||||||
mainPanel.add(gamePanel, "game");
|
add(gamePanel, "game");
|
||||||
|
|
||||||
// Frame-Layout einstellen
|
|
||||||
frame.add(mainPanel);
|
|
||||||
frame.setVisible(true);
|
|
||||||
|
|
||||||
// Timer starten
|
// Timer starten
|
||||||
startTimer();
|
startTimer();
|
||||||
|
@ -58,8 +44,8 @@ public class coinToss {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// Wechsel zum Spiel-Panel
|
// Wechsel zum Spiel-Panel
|
||||||
CardLayout cardLayout = (CardLayout) mainPanel.getLayout();
|
CardLayout cardLayout = (CardLayout) getLayout();
|
||||||
cardLayout.show(mainPanel, "game");
|
cardLayout.show(coinToss.this, "game");
|
||||||
timer.stop(); // Timer stoppen
|
timer.stop(); // Timer stoppen
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -67,37 +53,3 @@ public class coinToss {
|
||||||
timer.start(); // Timer starten
|
timer.start(); // Timer starten
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
|
|
||||||
TODO:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class coinToss {
|
|
||||||
// Funktionshilfen
|
|
||||||
|
|
||||||
|
|
||||||
// Frame
|
|
||||||
JFrame frame = new JFrame("Zugreihenfolge");
|
|
||||||
|
|
||||||
// Labels
|
|
||||||
JLabel frameTitle = new JLabel("Zugreihenfolge");
|
|
||||||
|
|
||||||
coinToss() {
|
|
||||||
// Erstelle Frame
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.setSize(1500, 1000);
|
|
||||||
|
|
||||||
// Layout Manager (absolute ositionierung)
|
|
||||||
frame.setLayout(null);
|
|
||||||
}
|
|
||||||
}*/
|
|
|
@ -1,5 +1,7 @@
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class startLocalGame extends JPanel {
|
public class startLocalGame extends JPanel {
|
||||||
// Funktionshilfen
|
// Funktionshilfen
|
||||||
|
@ -107,15 +109,41 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
leftPlayerLeftButton.addActionListener(e -> toggleLeftPlayerIcon());
|
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
leftPlayerRightButton.addActionListener(e -> toggleLeftPlayerIcon());
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleLeftPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
rightPlayerLeftButton.addActionListener(e -> toggleRightPlayerIcon());
|
leftPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
rightPlayerRightButton.addActionListener(e -> toggleRightPlayerIcon());
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleLeftPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
rightPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleRightPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
toggleRightPlayerIcon();
|
||||||
|
updateTextFields();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
||||||
|
|
||||||
startButton.addActionListener(e -> frame.showPanel("MainMenu")); // TODO ECHTE FUNKTION EINFÜGEN
|
startButton.addActionListener(e -> frame.showPanel("coinToss")); // TODO ECHTE FUNKTION EINFÜGEN
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleLeftPlayerIcon() {
|
private void toggleLeftPlayerIcon() {
|
||||||
|
@ -133,4 +161,21 @@ public class startLocalGame extends JPanel {
|
||||||
rightPlayerIcon.setIcon(humanPlayerIcon);
|
rightPlayerIcon.setIcon(humanPlayerIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Methode zum Aktualisieren der Textfelder basierend auf den ausgewählten Icons
|
||||||
|
private void updateTextFields() {
|
||||||
|
// Linker Spieler
|
||||||
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
leftPlayerTextField.setText("Spieler 1");
|
||||||
|
} else {
|
||||||
|
leftPlayerTextField.setText("Leicht");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rechter Spieler
|
||||||
|
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
rightPlayerTextField.setText("Spieler 2");
|
||||||
|
} else {
|
||||||
|
rightPlayerTextField.setText("Leicht");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue