Klasse fuer verbinden Panel erstellt(extrem grobes Beispiel) und Panel Weiterleitung eingefuegt

Anpassungen an ActionListenern in MainMenuView

Backbutton mit Funktion eingefuegt fuer joinGame Panel
This commit is contained in:
Kaver 2024-12-02 19:04:34 +01:00
parent 2274a1e558
commit 3b9b1eaebb
4 changed files with 61 additions and 8 deletions

View File

@ -2,6 +2,8 @@ import java.awt.*;
import javax.swing.*;
public class JoinGame extends JPanel {
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
JLabel spielBeitretenLabel;
JLabel ipLabel = new JLabel("IP-Adresse");
JLabel portLabel = new JLabel("Port");
@ -10,6 +12,7 @@ public class JoinGame extends JPanel {
JTextField portTextField = new JTextField(20);
JButton losButton = new JButton("Los!");
JButton backButton = new JButton(backButtonIcon);
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
@ -27,6 +30,7 @@ public class JoinGame extends JPanel {
spielBeitretenLabel.setBounds(20,20,700, 100);
losButton.setBounds(320, 225, 100, 50);
backButton.setBounds(1380, 20, 80, 80);
ipLabel.setBounds(50, 125, 200, 30);
portLabel.setBounds(50, 200, 200, 30);
@ -43,6 +47,9 @@ public class JoinGame extends JPanel {
add(losButton);
add(ipTextField);
add(portTextField);
}
add(backButton);
backButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
losButton.addActionListener(e -> frame.showPanel("Verbinden"));
}
}

View File

@ -37,6 +37,7 @@ public class MainFrame extends JFrame {
startLocalGame localGame = new startLocalGame(this);
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
coinToss coinToss = new coinToss(this);
Verbinden verbinden = new Verbinden(this);
//JoinGame joinGame = new JoinGame(this,localMult);
//GameBoard gameBoard = new GameBoard(this, localMult);
@ -44,6 +45,7 @@ public class MainFrame extends JFrame {
mainPanel.add(localGame, "LocalGame");
mainPanel.add(multiplayerGame, "MultiplayerGame");
mainPanel.add(coinToss, "coinToss");
mainPanel.add(verbinden, "Verbinden");
//mainPanel.add(joinGame, "JoinGame");
//mainPanel.add(gameBoard, "GameBoard");
@ -64,8 +66,8 @@ public class MainFrame extends JFrame {
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
JoinGame joinGame = new JoinGame(this, localMult);
mainPanel.add(joinGame, panelName); // Dynamically add the panel
mainPanel.revalidate(); // Refresh the layout
mainPanel.add(joinGame, panelName);
mainPanel.revalidate(); // Refresh
mainPanel.repaint();
//}
@ -77,8 +79,8 @@ public class MainFrame extends JFrame {
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
GameBoard gameBoard = new GameBoard(this, semesterCounter);
mainPanel.add(gameBoard, panelName); // Dynamically add the panel
mainPanel.revalidate(); // Refresh the layout
mainPanel.add(gameBoard, panelName);
mainPanel.revalidate(); // Refresh
mainPanel.repaint();
//}

View File

@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.*;
@ -36,9 +37,29 @@ public class MainMenuView extends JPanel {
add(soundButton);
// Event Listener für Buttons
lokalButton.addActionListener(e -> frame.showPanel("LocalGame"));
multiButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
soundButton.addActionListener(e -> toggleMute());
lokalButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Lokales Spiel ausgewählt.");
frame.showPanel("LocalGame"); // Panel wechseln
}
});
multiButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Multiplayer-Spiel ausgewählt.");
frame.showPanel("MultiplayerGame"); // Panel wechseln
}
});
soundButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Soundbutton geklickt.");
toggleMute();
}
});
}
private void toggleMute() {

23
src/Verbinden.java Normal file
View File

@ -0,0 +1,23 @@
import javax.swing.*;
import java.awt.*;
public class Verbinden extends JPanel{
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
JLabel verbindenLabel = new JLabel("Verbinde . . .",SwingConstants.CENTER);
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
public Verbinden(MainFrame frame) {
setLayout(null);
buildPanel(frame);
}
private void buildPanel(MainFrame frame) {
setLayout(new BorderLayout());
verbindenLabel.setFont(robotoFont.deriveFont(50f));
add(verbindenLabel, BorderLayout.CENTER);
}
}