2019-07-06 16:37:42 +02:00
|
|
|
package dev.kske.chess.ui;
|
2019-07-01 18:26:43 +02:00
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.EventQueue;
|
2019-07-18 11:19:58 +02:00
|
|
|
import java.awt.Toolkit;
|
2019-07-01 18:26:43 +02:00
|
|
|
|
2019-07-03 11:05:20 +02:00
|
|
|
import javax.swing.JButton;
|
2019-07-01 18:26:43 +02:00
|
|
|
import javax.swing.JFrame;
|
2019-07-03 11:05:20 +02:00
|
|
|
import javax.swing.JPanel;
|
2019-07-01 18:26:43 +02:00
|
|
|
|
2019-07-14 12:03:45 +02:00
|
|
|
import dev.kske.chess.game.Game;
|
2019-07-01 18:26:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Project: <strong>Chess</strong><br>
|
2019-07-06 16:37:42 +02:00
|
|
|
* File: <strong>MainWindow.java</strong><br>
|
2019-07-01 18:26:43 +02:00
|
|
|
* Created: <strong>01.07.2019</strong><br>
|
|
|
|
* Author: <strong>Kai S. K. Engelbart</strong>
|
|
|
|
*/
|
2019-07-06 16:37:42 +02:00
|
|
|
public class MainWindow {
|
2019-07-01 18:26:43 +02:00
|
|
|
|
2019-07-16 11:58:51 +02:00
|
|
|
private JFrame mframe;
|
|
|
|
private BoardPane boardPane;
|
|
|
|
private Game game;
|
2019-07-01 18:26:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Launch the application.
|
|
|
|
*/
|
|
|
|
public static void main(String[] args) {
|
|
|
|
EventQueue.invokeLater(new Runnable() {
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
try {
|
2019-07-06 16:37:42 +02:00
|
|
|
MainWindow window = new MainWindow();
|
2019-07-01 18:26:43 +02:00
|
|
|
window.mframe.setVisible(true);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the application.
|
|
|
|
*/
|
2019-07-06 16:37:42 +02:00
|
|
|
public MainWindow() {
|
2019-07-01 18:26:43 +02:00
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the contents of the frame.
|
|
|
|
*/
|
|
|
|
private void initialize() {
|
|
|
|
mframe = new JFrame();
|
2019-07-02 22:06:48 +02:00
|
|
|
mframe.setResizable(false);
|
2019-07-03 11:05:20 +02:00
|
|
|
mframe.setBounds(100, 100, 494, 565);
|
2019-07-01 18:26:43 +02:00
|
|
|
mframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
2019-07-18 11:19:58 +02:00
|
|
|
mframe.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/pieces/king_white.png")));
|
|
|
|
|
2019-07-16 11:58:51 +02:00
|
|
|
boardPane = new BoardPane();
|
2019-07-09 09:20:30 +02:00
|
|
|
mframe.getContentPane().add(boardPane, BorderLayout.CENTER);
|
2019-07-03 11:05:20 +02:00
|
|
|
|
2019-07-16 11:58:51 +02:00
|
|
|
mframe.setJMenuBar(new MenuBar(this));
|
|
|
|
|
2019-07-03 11:05:20 +02:00
|
|
|
JPanel toolPanel = new JPanel();
|
|
|
|
mframe.getContentPane().add(toolPanel, BorderLayout.NORTH);
|
|
|
|
|
|
|
|
JButton btnRestart = new JButton("Restart");
|
2019-07-16 18:24:48 +02:00
|
|
|
btnRestart.addActionListener((evt) -> { if (game != null) game.reset(); game.start(); });
|
2019-07-23 09:31:20 +02:00
|
|
|
|
|
|
|
JButton btnSwapColors = new JButton("Swap Colors");
|
|
|
|
btnSwapColors.addActionListener((evt) -> game.swapColors());
|
|
|
|
|
2019-07-03 11:05:20 +02:00
|
|
|
toolPanel.add(btnRestart);
|
2019-07-23 09:31:20 +02:00
|
|
|
toolPanel.add(btnSwapColors);
|
|
|
|
|
2019-07-02 22:06:48 +02:00
|
|
|
mframe.pack();
|
2019-07-13 11:38:44 +02:00
|
|
|
mframe.setLocationRelativeTo(null);
|
2019-07-01 18:26:43 +02:00
|
|
|
}
|
2019-07-14 12:03:45 +02:00
|
|
|
|
2019-07-16 11:58:51 +02:00
|
|
|
public BoardPane getBoardPane() { return boardPane; }
|
|
|
|
|
2019-07-14 12:03:45 +02:00
|
|
|
public Game getGame() { return game; }
|
|
|
|
|
2019-07-21 14:35:14 +02:00
|
|
|
public void setGame(Game game) {
|
|
|
|
if (this.game != null) this.game.disconnect();
|
|
|
|
this.game = game;
|
|
|
|
}
|
2019-07-01 18:26:43 +02:00
|
|
|
}
|