Umstrukturierung von MainFrame, sodass beim druecken eines Buttons parameter an die Funktion uebergeben werden welche das naechste Panel stellt (showPanelExtra)
This commit is contained in:
parent
1fc1abee3a
commit
5cabd5325a
|
@ -4,7 +4,7 @@ import javax.swing.JFrame;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class JoinGame extends JPanel {
|
public class JoinGame extends JPanel {
|
||||||
JLabel spielBeitretenLabel= new JLabel("Spiel beitreten");
|
JLabel spielBeitretenLabel;
|
||||||
JLabel ipLabel = new JLabel("IP-Adresse");
|
JLabel ipLabel = new JLabel("IP-Adresse");
|
||||||
JLabel portLabel = new JLabel("Port");
|
JLabel portLabel = new JLabel("Port");
|
||||||
|
|
||||||
|
@ -15,12 +15,18 @@ public class JoinGame extends JPanel {
|
||||||
|
|
||||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||||
|
|
||||||
public JoinGame(MainFrame frame) {
|
public JoinGame(MainFrame frame,int g) {
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
buildPanel(frame);
|
buildPanel(frame,g);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildPanel(MainFrame frame) {
|
private void buildPanel(MainFrame frame,int g) {
|
||||||
|
if(g==1){
|
||||||
|
spielBeitretenLabel= new JLabel("Spiel beitreten");
|
||||||
|
}else{
|
||||||
|
spielBeitretenLabel= new JLabel("Spiel erstellen");
|
||||||
|
}
|
||||||
|
|
||||||
spielBeitretenLabel.setBounds(20,20,700, 100);
|
spielBeitretenLabel.setBounds(20,20,700, 100);
|
||||||
losButton.setBounds(320, 225, 100, 50);
|
losButton.setBounds(320, 225, 100, 50);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
private CardLayout cardLayout;
|
private CardLayout cardLayout;
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
|
int localMult;
|
||||||
|
|
||||||
public MainFrame() {
|
public MainFrame() {
|
||||||
setTitle("Studium Versenken");
|
setTitle("Studium Versenken");
|
||||||
|
@ -27,13 +28,13 @@ 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);
|
||||||
JoinGame joinGame = new JoinGame(this);
|
//JoinGame joinGame = new JoinGame(this,localMult);
|
||||||
|
|
||||||
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");
|
mainPanel.add(coinToss, "coinToss");
|
||||||
mainPanel.add(joinGame, "JoinGame");
|
//mainPanel.add(joinGame, "JoinGame");
|
||||||
// Hauptpanel in JFrame hinzufügen
|
// Hauptpanel in JFrame hinzufügen
|
||||||
add(mainPanel);
|
add(mainPanel);
|
||||||
|
|
||||||
|
@ -46,6 +47,27 @@ public class MainFrame extends JFrame {
|
||||||
cardLayout.show(mainPanel, panelName);
|
cardLayout.show(mainPanel, panelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showPanelExtra(String panelName,int num) {
|
||||||
|
this.localMult = num;
|
||||||
|
|
||||||
|
if (!isPanelPresent(panelName)) {
|
||||||
|
JoinGame joinGame = new JoinGame(this, localMult);
|
||||||
|
mainPanel.add(joinGame, panelName); // Dynamically add the panel
|
||||||
|
mainPanel.revalidate(); // Refresh the layout
|
||||||
|
mainPanel.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
cardLayout.show(mainPanel, panelName); // Show the panel
|
||||||
|
}
|
||||||
|
private boolean isPanelPresent(String panelName) {
|
||||||
|
for (Component component : mainPanel.getComponents()) {
|
||||||
|
if (panelName.equals(mainPanel.getClientProperty("name"))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
MainFrame frame = new MainFrame();
|
MainFrame frame = new MainFrame();
|
||||||
|
|
|
@ -6,7 +6,8 @@ public class startMultiplayerGame extends JPanel {
|
||||||
// Funktionshilfen
|
// Funktionshilfen
|
||||||
int semesterCounter = 1; // Semester Counter Label
|
int semesterCounter = 1; // Semester Counter Label
|
||||||
String PlayerNickname = "Spieler 1";
|
String PlayerNickname = "Spieler 1";
|
||||||
|
int multlocal;
|
||||||
|
String test;
|
||||||
// Grafiken
|
// Grafiken
|
||||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||||
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
||||||
|
@ -109,7 +110,8 @@ public class startMultiplayerGame extends JPanel {
|
||||||
// ActionListener für den "Back" Button, um zum vorherigen Panel zurückzukehren
|
// ActionListener für den "Back" Button, um zum vorherigen Panel zurückzukehren
|
||||||
|
|
||||||
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
||||||
joinGameButton.addActionListener(e -> frame.showPanel("JoinGame"));
|
joinGameButton.addActionListener(e -> frame.showPanelExtra("JoinGame",1));
|
||||||
|
createGameButton.addActionListener(e -> frame.showPanelExtra("JoinGame",0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOGGLE METHODEN
|
// TOGGLE METHODEN
|
||||||
|
|
Loading…
Reference in New Issue