Compare commits
2 Commits
1fc1abee3a
...
88d016ed99
Author | SHA1 | Date |
---|---|---|
|
88d016ed99 | |
|
5cabd5325a |
|
@ -1,10 +1,8 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.*;
|
||||
|
||||
public class JoinGame extends JPanel {
|
||||
JLabel spielBeitretenLabel= new JLabel("Spiel beitreten");
|
||||
JLabel spielBeitretenLabel;
|
||||
JLabel ipLabel = new JLabel("IP-Adresse");
|
||||
JLabel portLabel = new JLabel("Port");
|
||||
|
||||
|
@ -15,12 +13,18 @@ public class JoinGame extends JPanel {
|
|||
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
|
||||
public JoinGame(MainFrame frame) {
|
||||
public JoinGame(MainFrame frame,int g) {
|
||||
setLayout(null);
|
||||
buildPanel(frame);
|
||||
buildPanel(frame,g);
|
||||
}
|
||||
|
||||
private void buildPanel(MainFrame frame,int g) {
|
||||
if(g==1){
|
||||
spielBeitretenLabel= new JLabel("Spiel beitreten");
|
||||
}else{
|
||||
spielBeitretenLabel= new JLabel("Spiel erstellen");
|
||||
}
|
||||
|
||||
private void buildPanel(MainFrame frame) {
|
||||
spielBeitretenLabel.setBounds(20,20,700, 100);
|
||||
losButton.setBounds(320, 225, 100, 50);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ public class MainFrame extends JFrame {
|
|||
|
||||
private CardLayout cardLayout;
|
||||
private JPanel mainPanel;
|
||||
int localMult;
|
||||
|
||||
public MainFrame() {
|
||||
setTitle("Studium Versenken");
|
||||
|
@ -27,13 +28,13 @@ public class MainFrame extends JFrame {
|
|||
startLocalGame localGame = new startLocalGame(this);
|
||||
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
|
||||
coinToss coinToss = new coinToss(this);
|
||||
JoinGame joinGame = new JoinGame(this);
|
||||
//JoinGame joinGame = new JoinGame(this,localMult);
|
||||
|
||||
mainPanel.add(mainMenuView, "MainMenu");
|
||||
mainPanel.add(localGame, "LocalGame");
|
||||
mainPanel.add(multiplayerGame, "MultiplayerGame");
|
||||
mainPanel.add(coinToss, "coinToss");
|
||||
mainPanel.add(joinGame, "JoinGame");
|
||||
//mainPanel.add(joinGame, "JoinGame");
|
||||
// Hauptpanel in JFrame hinzufügen
|
||||
add(mainPanel);
|
||||
|
||||
|
@ -46,6 +47,27 @@ public class MainFrame extends JFrame {
|
|||
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) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
MainFrame frame = new MainFrame();
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class startMultiplayerGame extends JPanel {
|
||||
// Funktionshilfen
|
||||
int semesterCounter = 1; // Semester Counter Label
|
||||
String PlayerNickname = "Spieler 1";
|
||||
|
||||
// Grafiken
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
||||
|
@ -109,7 +106,8 @@ public class startMultiplayerGame extends JPanel {
|
|||
// ActionListener für den "Back" Button, um zum vorherigen Panel zurückzukehren
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue