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: Chess
* File: GameConfigurationDialog.java
* Created: 24.07.2019
* Author: Kai S. K. Engelbart */ 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 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 cbWhite = new JComboBox<>(); cbWhite.setModel(new DefaultComboBoxModel(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 cbBlack = new JComboBox<>(); cbBlack.setModel(new DefaultComboBoxModel(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; } }