Refactor MainGui to use callback for game start
parent
e9e8c7e650
commit
1613ab575f
|
|
@ -8,10 +8,12 @@ import de.hs_mannheim.informatik.chess.view.MainGui;
|
||||||
public class Main{
|
public class Main{
|
||||||
|
|
||||||
public static void main( String[] args ){
|
public static void main( String[] args ){
|
||||||
new MainGui();
|
new MainGui(() -> {
|
||||||
|
//Wenn "Normal Modus" gedrückt wird
|
||||||
GameGui gui = new GameGui();
|
GameGui gui = new GameGui();
|
||||||
ChessEngine engine = new ChessEngine();
|
ChessEngine engine = new ChessEngine();
|
||||||
new Controller(gui, engine);
|
new Controller(gui, engine);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,78 @@
|
||||||
package de.hs_mannheim.informatik.chess.view;
|
package de.hs_mannheim.informatik.chess.view;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
public class MainGui {
|
public class MainGui {
|
||||||
|
|
||||||
|
private JFrame frame;
|
||||||
|
private Runnable onStartGame;
|
||||||
|
|
||||||
|
public MainGui(Runnable onStartGame) {
|
||||||
|
this.onStartGame = onStartGame;
|
||||||
|
|
||||||
|
frame = new JFrame("Chess - Hauptmenü");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setSize(800, 600);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
//Haupt-Panel mit GridBagLayout
|
||||||
|
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||||
|
mainPanel.setBackground(new Color(0xe0e1dd));
|
||||||
|
|
||||||
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
gbc.gridx = 0;
|
||||||
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc.insets = new Insets(15, 0, 15, 0);
|
||||||
|
|
||||||
|
//Title
|
||||||
|
JLabel title = new JLabel("Chess", SwingConstants.CENTER);
|
||||||
|
title.setFont(new Font("Serif", Font.BOLD, 70));
|
||||||
|
title.setForeground(new Color(0x1b263b));
|
||||||
|
gbc.gridy = 0;
|
||||||
|
gbc.ipady = 50;
|
||||||
|
mainPanel.add(title, gbc);
|
||||||
|
|
||||||
|
//Abstand nach unten
|
||||||
|
gbc.gridy = 1;
|
||||||
|
gbc.ipady = 15;
|
||||||
|
mainPanel.add(Box.createRigidArea(new Dimension(0, 60)), gbc);
|
||||||
|
|
||||||
|
//Buttons
|
||||||
|
JButton btnMode1 = new JButton("Normal Modus");
|
||||||
|
JButton btnMode2 = new JButton("Modus 2 (coming soon)");
|
||||||
|
JButton btnMode3 = new JButton("Modus 3 (coming soon)");
|
||||||
|
|
||||||
|
styleButton(btnMode1);
|
||||||
|
styleButton(btnMode2);
|
||||||
|
styleButton(btnMode3);
|
||||||
|
|
||||||
|
gbc.gridy = 2; gbc.ipady = 25;
|
||||||
|
mainPanel.add(btnMode1, gbc);
|
||||||
|
|
||||||
|
gbc.gridy = 3;
|
||||||
|
mainPanel.add(btnMode2, gbc);
|
||||||
|
|
||||||
|
gbc.gridy = 4;
|
||||||
|
mainPanel.add(btnMode3, gbc);
|
||||||
|
|
||||||
|
frame.add(mainPanel);
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
//Button ActionListener für "Normal Modus"
|
||||||
|
btnMode1.addActionListener(e -> {
|
||||||
|
frame.dispose(); // Hauptmenü schließen
|
||||||
|
onStartGame.run(); // **Ruft den Callback auf**
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper für Button Styling
|
||||||
|
private void styleButton(JButton btn) {
|
||||||
|
btn.setFont(new Font("Serif", Font.BOLD, 30));
|
||||||
|
btn.setBackground(new Color(0x778da9));
|
||||||
|
btn.setForeground(Color.WHITE);
|
||||||
|
btn.setFocusPainted(false);
|
||||||
|
btn.setBorder(BorderFactory.createEmptyBorder(10, 40, 10, 40));
|
||||||
|
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue