Implemented custom board config dialog
This commit is contained in:
parent
948fa50d40
commit
feb519c7cc
@ -13,7 +13,6 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JSlider;
|
import javax.swing.JSlider;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Project: <strong>Minesweeper</strong><br>
|
* Project: <strong>Minesweeper</strong><br>
|
||||||
* File: <strong>CustomDialog.java</strong><br>
|
* File: <strong>CustomDialog.java</strong><br>
|
||||||
@ -24,7 +23,8 @@ public class CustomDialog extends JDialog {
|
|||||||
|
|
||||||
private static final long serialVersionUID = -4019516811065781434L;
|
private static final long serialVersionUID = -4019516811065781434L;
|
||||||
private final JPanel mcontentPanel = new JPanel();
|
private final JPanel mcontentPanel = new JPanel();
|
||||||
private final JSlider sliderBoardWidth, sliderBoardHeight, sliderNumMines;
|
|
||||||
|
private BoardConfig result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the dialog.
|
* Create the dialog.
|
||||||
@ -43,13 +43,11 @@ public class CustomDialog extends JDialog {
|
|||||||
lblBoardWidth.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
lblBoardWidth.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
||||||
mcontentPanel.add(lblBoardWidth);
|
mcontentPanel.add(lblBoardWidth);
|
||||||
}
|
}
|
||||||
{
|
JSlider sliderBoardWidth = new JSlider();
|
||||||
sliderBoardWidth = new JSlider();
|
|
||||||
sliderBoardWidth.setValue(16);
|
sliderBoardWidth.setValue(16);
|
||||||
sliderBoardWidth.setMinimum(2);
|
sliderBoardWidth.setMinimum(2);
|
||||||
sliderBoardWidth.setMaximum(30);
|
sliderBoardWidth.setMaximum(30);
|
||||||
mcontentPanel.add(sliderBoardWidth);
|
mcontentPanel.add(sliderBoardWidth);
|
||||||
}
|
|
||||||
{
|
{
|
||||||
JLabel label = new JLabel("");
|
JLabel label = new JLabel("");
|
||||||
mcontentPanel.add(label);
|
mcontentPanel.add(label);
|
||||||
@ -59,13 +57,11 @@ public class CustomDialog extends JDialog {
|
|||||||
lblBoardHeight.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
lblBoardHeight.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
||||||
mcontentPanel.add(lblBoardHeight);
|
mcontentPanel.add(lblBoardHeight);
|
||||||
}
|
}
|
||||||
{
|
JSlider sliderBoardHeight = new JSlider();
|
||||||
sliderBoardHeight = new JSlider();
|
|
||||||
sliderBoardHeight.setValue(16);
|
sliderBoardHeight.setValue(16);
|
||||||
sliderBoardHeight.setMaximum(30);
|
sliderBoardHeight.setMaximum(30);
|
||||||
sliderBoardHeight.setMinimum(2);
|
sliderBoardHeight.setMinimum(2);
|
||||||
mcontentPanel.add(sliderBoardHeight);
|
mcontentPanel.add(sliderBoardHeight);
|
||||||
}
|
|
||||||
{
|
{
|
||||||
JLabel label = new JLabel("");
|
JLabel label = new JLabel("");
|
||||||
mcontentPanel.add(label);
|
mcontentPanel.add(label);
|
||||||
@ -75,13 +71,11 @@ public class CustomDialog extends JDialog {
|
|||||||
lblNumberOfMines.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
lblNumberOfMines.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
||||||
mcontentPanel.add(lblNumberOfMines);
|
mcontentPanel.add(lblNumberOfMines);
|
||||||
}
|
}
|
||||||
{
|
JSlider sliderNumMines = new JSlider();
|
||||||
sliderNumMines = new JSlider();
|
|
||||||
sliderNumMines.setValue(16);
|
sliderNumMines.setValue(16);
|
||||||
sliderNumMines.setMinimum(2);
|
sliderNumMines.setMinimum(2);
|
||||||
sliderNumMines.setMaximum(200);
|
sliderNumMines.setMaximum(200);
|
||||||
mcontentPanel.add(sliderNumMines);
|
mcontentPanel.add(sliderNumMines);
|
||||||
}
|
|
||||||
{
|
{
|
||||||
JLabel label = new JLabel("");
|
JLabel label = new JLabel("");
|
||||||
mcontentPanel.add(label);
|
mcontentPanel.add(label);
|
||||||
@ -93,6 +87,11 @@ public class CustomDialog extends JDialog {
|
|||||||
{
|
{
|
||||||
JButton okButton = new JButton("Start Game");
|
JButton okButton = new JButton("Start Game");
|
||||||
okButton.setActionCommand("OK");
|
okButton.setActionCommand("OK");
|
||||||
|
okButton.addActionListener((evt) -> {
|
||||||
|
result = new BoardConfig(sliderBoardWidth.getValue(), sliderBoardHeight.getValue(),
|
||||||
|
sliderNumMines.getValue());
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
buttonPane.add(okButton);
|
buttonPane.add(okButton);
|
||||||
getRootPane().setDefaultButton(okButton);
|
getRootPane().setDefaultButton(okButton);
|
||||||
}
|
}
|
||||||
@ -103,9 +102,10 @@ public class CustomDialog extends JDialog {
|
|||||||
buttonPane.add(cancelButton);
|
buttonPane.add(cancelButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setVisible(true);
|
|
||||||
}
|
}
|
||||||
public BoardConfig getBoardConfig() {
|
|
||||||
return new BoardConfig(sliderBoardWidth.getValue(), sliderBoardHeight.getValue(), sliderNumMines.getValue());
|
public BoardConfig showDialog() {
|
||||||
|
setVisible(true);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,10 @@ public class Minesweeper {
|
|||||||
easyMenuItem.addActionListener((evt) -> initGame(easyConfig));
|
easyMenuItem.addActionListener((evt) -> initGame(easyConfig));
|
||||||
mediumMenuItem.addActionListener((evt) -> initGame(mediumConfig));
|
mediumMenuItem.addActionListener((evt) -> initGame(mediumConfig));
|
||||||
hardMenuItem.addActionListener((evt) -> initGame(hardConfig));
|
hardMenuItem.addActionListener((evt) -> initGame(hardConfig));
|
||||||
|
customMenuItem.addActionListener((evt) -> {
|
||||||
|
BoardConfig cfg = new CustomDialog(mframe).showDialog();
|
||||||
|
if (cfg != null) initGame(cfg);
|
||||||
|
});
|
||||||
aboutMenuItem.addActionListener((evt) -> {
|
aboutMenuItem.addActionListener((evt) -> {
|
||||||
JOptionPane.showMessageDialog(board, "Minesweeper version " + VERSION + "\nby Kai S. K. Engelbart");
|
JOptionPane.showMessageDialog(board, "Minesweeper version " + VERSION + "\nby Kai S. K. Engelbart");
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user