Fehler beim Laden des Hauptmenüs behoben
parent
078d653921
commit
7139741018
|
@ -33,5 +33,6 @@ public class HitoriSolutionLoader {
|
|||
}
|
||||
|
||||
return solutionCoordinates;
|
||||
|
||||
}
|
||||
}
|
|
@ -227,14 +227,19 @@ public class GameBoard extends JPanel {
|
|||
}
|
||||
|
||||
private void returnToMainMenu() {
|
||||
// Eltern-Frame abrufen
|
||||
/// Eltern-Frame abrufen
|
||||
JFrame parentFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
|
||||
|
||||
// Inhalt des Frames auf das Hauptmenü setzen
|
||||
parentFrame.getContentPane().removeAll();
|
||||
parentFrame.add(new StartMenu());
|
||||
parentFrame.revalidate();
|
||||
parentFrame.repaint();
|
||||
if (parentFrame != null) {
|
||||
// Hauptmenü erstellen und im Frame setzen
|
||||
StartMenu startMenu = new StartMenu(parentFrame);
|
||||
parentFrame.getContentPane().removeAll(); // Entferne alle aktuellen Inhalte
|
||||
parentFrame.add(startMenu); // Füge das Hauptmenü hinzu
|
||||
parentFrame.revalidate(); // Layout aktualisieren
|
||||
parentFrame.repaint(); // Oberfläche neu zeichnen
|
||||
} else {
|
||||
System.err.println("Fehler: Kein übergeordnetes JFrame gefunden.");
|
||||
}
|
||||
}
|
||||
|
||||
private JButton createButton(String text, int width, int height) {
|
||||
|
|
|
@ -13,15 +13,14 @@ import java.util.Random;
|
|||
|
||||
import static PR2.HitoriSpiel.GUI.BoardLoader.loadBoard;
|
||||
|
||||
public class StartMenu extends JFrame {
|
||||
private JPanel mainPanel;
|
||||
public class StartMenu extends JPanel {
|
||||
private final JFrame parentFrame;
|
||||
|
||||
public StartMenu() {
|
||||
setTitle("Hitori - Hauptmenü");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(800, 600);
|
||||
public StartMenu(JFrame parentFrame) {
|
||||
this.parentFrame = parentFrame;
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
mainPanel = new JPanel(new GridBagLayout());
|
||||
//mainPanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = GridBagConstraints.RELATIVE;
|
||||
|
@ -31,7 +30,7 @@ public class StartMenu extends JFrame {
|
|||
JLabel titleLabel = new JLabel("Willkommen im Hitori-Spiel!");
|
||||
titleLabel.setFont(new Font("Arial", Font.BOLD, 16));
|
||||
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
mainPanel.add(titleLabel, gbc);
|
||||
add(titleLabel, gbc);
|
||||
|
||||
|
||||
// Buttons erstellen
|
||||
|
@ -42,11 +41,11 @@ public class StartMenu extends JFrame {
|
|||
JButton exitButton = createButton("Spiel beenden", 200, 30);
|
||||
|
||||
|
||||
mainPanel.add(continueButton, gbc);
|
||||
mainPanel.add(selectBoardButton, gbc);
|
||||
mainPanel.add(randomBoardButton, gbc);
|
||||
mainPanel.add(highscorelistButton, gbc);
|
||||
mainPanel.add(exitButton, gbc);
|
||||
add(continueButton, gbc);
|
||||
add(selectBoardButton, gbc);
|
||||
add(randomBoardButton, gbc);
|
||||
add(highscorelistButton, gbc);
|
||||
add(exitButton, gbc);
|
||||
|
||||
continueButton.addActionListener(e -> continueGame());
|
||||
selectBoardButton.addActionListener(e -> selectBoard());
|
||||
|
@ -54,9 +53,6 @@ public class StartMenu extends JFrame {
|
|||
highscorelistButton.addActionListener(e -> highscorelist());
|
||||
exitButton.addActionListener(e -> System.exit(0));
|
||||
|
||||
add(mainPanel);
|
||||
setVisible(true);
|
||||
setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
private void continueGame() {
|
||||
|
@ -125,11 +121,11 @@ public class StartMenu extends JFrame {
|
|||
}
|
||||
|
||||
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
|
||||
mainPanel.removeAll();
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
mainPanel.add(gameBoard, BorderLayout.CENTER);
|
||||
mainPanel.revalidate();
|
||||
mainPanel.repaint();
|
||||
removeAll();
|
||||
setLayout(new BorderLayout());
|
||||
add(gameBoard, BorderLayout.CENTER);
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void loadAndDisplayBoard(String selectedFile) {
|
||||
|
@ -154,4 +150,7 @@ public class StartMenu extends JFrame {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,14 +12,15 @@ import javax.swing.*;
|
|||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
new StartMenu();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null, "Ein schwerer Fehler ist aufgetreten: " + e.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
JFrame frame = new JFrame("Hitori - Hauptmenü");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(800, 600);
|
||||
frame.setLocationRelativeTo(null);
|
||||
|
||||
StartMenu startMenu = new StartMenu(frame);
|
||||
frame.add(startMenu);
|
||||
frame.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue