81 lines
1.9 KiB
Java
81 lines
1.9 KiB
Java
package dev.kske.chess.ui;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.EventQueue;
|
|
import java.awt.Toolkit;
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
|
|
import dev.kske.chess.game.Game;
|
|
|
|
/**
|
|
* Project: <strong>Chess</strong><br>
|
|
* File: <strong>MainWindow.java</strong><br>
|
|
* Created: <strong>01.07.2019</strong><br>
|
|
* Author: <strong>Kai S. K. Engelbart</strong>
|
|
*/
|
|
public class MainWindow {
|
|
|
|
private JFrame mframe;
|
|
private BoardPane boardPane;
|
|
private Game game;
|
|
|
|
/**
|
|
* Launch the application.
|
|
*/
|
|
public static void main(String[] args) {
|
|
EventQueue.invokeLater(new Runnable() {
|
|
|
|
public void run() {
|
|
try {
|
|
MainWindow window = new MainWindow();
|
|
window.mframe.setVisible(true);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Create the application.
|
|
*/
|
|
public MainWindow() {
|
|
initialize();
|
|
}
|
|
|
|
/**
|
|
* Initialize the contents of the frame.
|
|
*/
|
|
private void initialize() {
|
|
mframe = new JFrame();
|
|
mframe.setResizable(false);
|
|
mframe.setBounds(100, 100, 494, 565);
|
|
mframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
mframe.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/pieces/king_white.png")));
|
|
|
|
boardPane = new BoardPane();
|
|
mframe.getContentPane().add(boardPane, BorderLayout.CENTER);
|
|
|
|
mframe.setJMenuBar(new MenuBar(this));
|
|
|
|
JPanel toolPanel = new JPanel();
|
|
mframe.getContentPane().add(toolPanel, BorderLayout.NORTH);
|
|
|
|
JButton btnRestart = new JButton("Restart");
|
|
btnRestart.addActionListener((evt) -> { if (game != null) game.reset(); game.start(); });
|
|
toolPanel.add(btnRestart);
|
|
mframe.pack();
|
|
mframe.setLocationRelativeTo(null);
|
|
}
|
|
|
|
public BoardPane getBoardPane() { return boardPane; }
|
|
|
|
public Game getGame() { return game; }
|
|
|
|
public void setGame(Game game) { this.game = game; }
|
|
}
|