Working on custom game options dialog

This commit is contained in:
Kai S. K. Engelbart 2019-04-04 18:10:18 +02:00
parent 5535a59a73
commit 75b1bff0a1
2 changed files with 71 additions and 16 deletions

View File

@ -2,10 +2,15 @@ package dev.kske.minesweeper;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.border.EmptyBorder;
@ -20,34 +25,72 @@ public class CustomDialog extends JDialog {
private static final long serialVersionUID = -4019516811065781434L;
private final JPanel mcontentPanel = new JPanel();
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
CustomDialog dialog = new CustomDialog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public CustomDialog() {
public CustomDialog(Frame owner) {
super(owner, ModalityType.APPLICATION_MODAL);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
mcontentPanel.setLayout(new FlowLayout());
mcontentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(mcontentPanel, BorderLayout.CENTER);
mcontentPanel.setLayout(new GridLayout(0, 3, 0, 0));
{
JLabel lblBoardWidth = new JLabel("Board Width:");
lblBoardWidth.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblBoardWidth);
}
{
JSlider sliderBoardWidth = new JSlider();
sliderBoardWidth.setValue(16);
sliderBoardWidth.setMinimum(2);
sliderBoardWidth.setMaximum(30);
mcontentPanel.add(sliderBoardWidth);
}
{
JLabel label = new JLabel("");
mcontentPanel.add(label);
}
{
JLabel lblBoardHeight = new JLabel("Board Height:");
lblBoardHeight.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblBoardHeight);
}
{
JSlider sliderBoardHeight = new JSlider();
sliderBoardHeight.setValue(16);
sliderBoardHeight.setMaximum(30);
sliderBoardHeight.setMinimum(2);
mcontentPanel.add(sliderBoardHeight);
}
{
JLabel label = new JLabel("");
mcontentPanel.add(label);
}
{
JLabel lblNumberOfMines = new JLabel("Number of Mines:");
lblNumberOfMines.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblNumberOfMines);
}
{
JSlider slider = new JSlider();
slider.setValue(16);
slider.setMinimum(2);
slider.setMaximum(200);
mcontentPanel.add(slider);
}
{
JLabel label = new JLabel("");
mcontentPanel.add(label);
}
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
JButton okButton = new JButton("Start Game");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
@ -58,6 +101,7 @@ public class CustomDialog extends JDialog {
buttonPane.add(cancelButton);
}
}
setVisible(true);
}
}

View File

@ -14,6 +14,7 @@ import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
/**
* Project: <strong>Minesweeper</strong><br>
@ -59,6 +60,12 @@ public class Minesweeper {
* Initialize the contents of the frame.
*/
private void initialize() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
ex.printStackTrace();
}
mframe = new JFrame();
mframe.setResizable(false);
mframe.setTitle("Minesweeper");
@ -127,6 +134,10 @@ public class Minesweeper {
easyMenuItem.addActionListener((evt) -> initGame(easyConfig));
mediumMenuItem.addActionListener((evt) -> initGame(mediumConfig));
hardMenuItem.addActionListener((evt) -> initGame(hardConfig));
customMenuItem.addActionListener((evt) -> {
var dlg = new CustomDialog(mframe);
});
aboutMenuItem.addActionListener((evt) -> {
JOptionPane.showMessageDialog(board, "Minesweeper version " + VERSION + "\nby Kai S. K. Engelbart");
});