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:
parent
2274a1e558
commit
3b9b1eaebb
|
@ -2,6 +2,8 @@ import java.awt.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class JoinGame extends JPanel {
|
public class JoinGame extends JPanel {
|
||||||
|
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||||
|
|
||||||
JLabel spielBeitretenLabel;
|
JLabel spielBeitretenLabel;
|
||||||
JLabel ipLabel = new JLabel("IP-Adresse");
|
JLabel ipLabel = new JLabel("IP-Adresse");
|
||||||
JLabel portLabel = new JLabel("Port");
|
JLabel portLabel = new JLabel("Port");
|
||||||
|
@ -10,6 +12,7 @@ public class JoinGame extends JPanel {
|
||||||
JTextField portTextField = new JTextField(20);
|
JTextField portTextField = new JTextField(20);
|
||||||
|
|
||||||
JButton losButton = new JButton("Los!");
|
JButton losButton = new JButton("Los!");
|
||||||
|
JButton backButton = new JButton(backButtonIcon);
|
||||||
|
|
||||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||||
|
|
||||||
|
@ -27,6 +30,7 @@ public class JoinGame extends JPanel {
|
||||||
|
|
||||||
spielBeitretenLabel.setBounds(20,20,700, 100);
|
spielBeitretenLabel.setBounds(20,20,700, 100);
|
||||||
losButton.setBounds(320, 225, 100, 50);
|
losButton.setBounds(320, 225, 100, 50);
|
||||||
|
backButton.setBounds(1380, 20, 80, 80);
|
||||||
|
|
||||||
ipLabel.setBounds(50, 125, 200, 30);
|
ipLabel.setBounds(50, 125, 200, 30);
|
||||||
portLabel.setBounds(50, 200, 200, 30);
|
portLabel.setBounds(50, 200, 200, 30);
|
||||||
|
@ -43,6 +47,9 @@ public class JoinGame extends JPanel {
|
||||||
add(losButton);
|
add(losButton);
|
||||||
add(ipTextField);
|
add(ipTextField);
|
||||||
add(portTextField);
|
add(portTextField);
|
||||||
}
|
add(backButton);
|
||||||
|
|
||||||
|
backButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
|
||||||
|
losButton.addActionListener(e -> frame.showPanel("Verbinden"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class MainFrame extends JFrame {
|
||||||
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);
|
coinToss coinToss = new coinToss(this);
|
||||||
|
Verbinden verbinden = new Verbinden(this);
|
||||||
//JoinGame joinGame = new JoinGame(this,localMult);
|
//JoinGame joinGame = new JoinGame(this,localMult);
|
||||||
//GameBoard gameBoard = new GameBoard(this, localMult);
|
//GameBoard gameBoard = new GameBoard(this, localMult);
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ public class MainFrame extends JFrame {
|
||||||
mainPanel.add(localGame, "LocalGame");
|
mainPanel.add(localGame, "LocalGame");
|
||||||
mainPanel.add(multiplayerGame, "MultiplayerGame");
|
mainPanel.add(multiplayerGame, "MultiplayerGame");
|
||||||
mainPanel.add(coinToss, "coinToss");
|
mainPanel.add(coinToss, "coinToss");
|
||||||
|
mainPanel.add(verbinden, "Verbinden");
|
||||||
//mainPanel.add(joinGame, "JoinGame");
|
//mainPanel.add(joinGame, "JoinGame");
|
||||||
//mainPanel.add(gameBoard, "GameBoard");
|
//mainPanel.add(gameBoard, "GameBoard");
|
||||||
|
|
||||||
|
@ -64,8 +66,8 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
||||||
JoinGame joinGame = new JoinGame(this, localMult);
|
JoinGame joinGame = new JoinGame(this, localMult);
|
||||||
mainPanel.add(joinGame, panelName); // Dynamically add the panel
|
mainPanel.add(joinGame, panelName);
|
||||||
mainPanel.revalidate(); // Refresh the layout
|
mainPanel.revalidate(); // Refresh
|
||||||
mainPanel.repaint();
|
mainPanel.repaint();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
@ -77,8 +79,8 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
||||||
GameBoard gameBoard = new GameBoard(this, semesterCounter);
|
GameBoard gameBoard = new GameBoard(this, semesterCounter);
|
||||||
mainPanel.add(gameBoard, panelName); // Dynamically add the panel
|
mainPanel.add(gameBoard, panelName);
|
||||||
mainPanel.revalidate(); // Refresh the layout
|
mainPanel.revalidate(); // Refresh
|
||||||
mainPanel.repaint();
|
mainPanel.repaint();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
@ -36,9 +37,29 @@ public class MainMenuView extends JPanel {
|
||||||
add(soundButton);
|
add(soundButton);
|
||||||
|
|
||||||
// Event Listener für Buttons
|
// Event Listener für Buttons
|
||||||
lokalButton.addActionListener(e -> frame.showPanel("LocalGame"));
|
lokalButton.addActionListener(new ActionListener() {
|
||||||
multiButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
|
@Override
|
||||||
soundButton.addActionListener(e -> toggleMute());
|
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() {
|
private void toggleMute() {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue