83 lines
2.5 KiB
Java
83 lines
2.5 KiB
Java
package dev.kske.chess.ui;
|
|
|
|
import java.awt.Font;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
import javax.swing.DefaultComboBoxModel;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JComboBox;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JLabel;
|
|
|
|
/**
|
|
* Project: <strong>Chess</strong><br>
|
|
* File: <strong>GameConfigurationDialog.java</strong><br>
|
|
* Created: <strong>24.07.2019</strong><br>
|
|
* Author: <strong>Kai S. K. Engelbart</strong>
|
|
*/
|
|
public class GameConfigurationDialog extends JDialog {
|
|
|
|
private static final long serialVersionUID = 9080577278529876972L;
|
|
|
|
private String whiteName, blackName;
|
|
private boolean startGame;
|
|
|
|
/**
|
|
* Create the dialog.
|
|
*/
|
|
public GameConfigurationDialog() {
|
|
setTitle("Game Configuration");
|
|
setBounds(100, 100, 281, 142);
|
|
setModal(true);
|
|
setLocationRelativeTo(null);
|
|
getContentPane().setLayout(null);
|
|
|
|
startGame = false;
|
|
List<String> options = new ArrayList<>(Arrays.asList("Natural Player", "AI Player"));
|
|
EngineUtil.getEngineInfos().forEach(info -> options.add(info.name));
|
|
|
|
JLabel lblWhite = new JLabel("White:");
|
|
lblWhite.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
|
lblWhite.setBounds(10, 11, 49, 14);
|
|
getContentPane().add(lblWhite);
|
|
|
|
JComboBox<Object> cbWhite = new JComboBox<>();
|
|
cbWhite.setModel(new DefaultComboBoxModel<Object>(options.toArray()));
|
|
cbWhite.setBounds(98, 9, 159, 22);
|
|
getContentPane().add(cbWhite);
|
|
|
|
JLabel lblBlack = new JLabel("Black:");
|
|
lblBlack.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
|
lblBlack.setBounds(10, 38, 49, 14);
|
|
getContentPane().add(lblBlack);
|
|
|
|
JComboBox<Object> cbBlack = new JComboBox<>();
|
|
cbBlack.setModel(new DefaultComboBoxModel<Object>(options.toArray()));
|
|
cbBlack.setBounds(98, 36, 159, 22);
|
|
getContentPane().add(cbBlack);
|
|
|
|
JButton btnStart = new JButton("Start");
|
|
btnStart.addActionListener((evt) -> {
|
|
startGame = true;
|
|
whiteName = options.get(cbWhite.getSelectedIndex());
|
|
blackName = options.get(cbBlack.getSelectedIndex());
|
|
dispose();
|
|
});
|
|
btnStart.setBounds(20, 73, 89, 23);
|
|
getContentPane().add(btnStart);
|
|
|
|
JButton btnCancel = new JButton("Cancel");
|
|
btnCancel.addActionListener((evt) -> dispose());
|
|
btnCancel.setBounds(157, 73, 89, 23);
|
|
getContentPane().add(btnCancel);
|
|
}
|
|
|
|
public String getWhiteName() { return whiteName; }
|
|
|
|
public String getBlackName() { return blackName; }
|
|
|
|
public boolean isStartGame() { return startGame; }
|
|
}
|