This repository has been archived on 2021-02-18. You can view files and clone it, but cannot push or open issues or pull requests.
chess/src/dev/kske/chess/ui/MainWindow.java

92 lines
2.2 KiB
Java

package dev.kske.chess.ui;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.dnd.DropTarget;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
/**
* 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 extends JFrame {
private static final long serialVersionUID = -3100939302567978977L;
private JTabbedPane tabbedPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
try {
new MainWindow();
} catch (Exception ex) {
ex.printStackTrace();
}
});
}
/**
* Create the application.
*/
public MainWindow() {
super("Chess by Kai S. K. Engelbart");
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
// Configure frame
setResizable(false);
setBounds(100, 100, 494, 565);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/pieces/queen_white.png")));
// Add frame content
tabbedPane = new JTabbedPane();
getContentPane().add(tabbedPane);
setJMenuBar(new MenuBar(this));
new DropTarget(this, new FENDropTarget(this));
// Update position and dimensions
pack();
setLocationRelativeTo(null);
setVisible(true);
}
/**
* @return The currently selected {@link GamePane} component
*/
public GamePane getSelectedGamePane() { return (GamePane) tabbedPane.getSelectedComponent(); }
/**
* Creates a new {@link GamePane}, adds it to the tabbed pane and opens it.
*
* @return The new {@link GamePane}
*/
public GamePane addGamePane() {
GamePane gamePane = new GamePane();
tabbedPane.add("Game " + (tabbedPane.getComponentCount() + 1), gamePane);
tabbedPane.setSelectedIndex(tabbedPane.getComponentCount() - 1);
return gamePane;
}
/**
* Removes a {@link GamePane} form the tabbed pane.
*
* @param index The index of the {@link GamePane} to remove
*/
public void removeGamePane(int index) {
tabbedPane.remove(index);
}
}