From 349855a4afc61b982b25cacd0d3f41b324cba813 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 10 Apr 2019 08:41:56 +0200 Subject: [PATCH] Cleanup --- src/dev/kske/minesweeper/Board.java | 27 +++++++------- src/dev/kske/minesweeper/CustomDialog.java | 43 +++++++++++----------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/dev/kske/minesweeper/Board.java b/src/dev/kske/minesweeper/Board.java index d0f888a..ceeb2c2 100644 --- a/src/dev/kske/minesweeper/Board.java +++ b/src/dev/kske/minesweeper/Board.java @@ -66,7 +66,6 @@ public class Board extends JPanel { case MouseEvent.BUTTON3: flagTile(n, m); } - if (gameState != GameState.ACTIVE) repaint(); } }); } @@ -80,7 +79,7 @@ public class Board extends JPanel { setPreferredSize(new Dimension(config.width * tileSize, config.height * tileSize)); gameState = GameState.ACTIVE; - this.mines = config.mines; + mines = config.mines; activeTiles = boardWidth * boardHeight; flaggedTiles = 0; @@ -97,18 +96,6 @@ public class Board extends JPanel { init(initialConfig); } - public void registerGameListener(GameListener listener) { - listeners.add(listener); - } - - private void notifyGameStateEvent(GameStateEvent evt) { - listeners.forEach(listener -> listener.onGameStateEvent(evt)); - } - - private void notifyFlaggedTilesEvent(FlaggedTilesEvent evt) { - listeners.forEach(listener -> listener.onFlaggedTilesEvent(evt)); - } - @Override public void paintComponent(Graphics g) { super.paintComponent(g); @@ -155,6 +142,18 @@ public class Board extends JPanel { } } + public void registerGameListener(GameListener listener) { + listeners.add(listener); + } + + private void notifyGameStateEvent(GameStateEvent evt) { + listeners.forEach(listener -> listener.onGameStateEvent(evt)); + } + + private void notifyFlaggedTilesEvent(FlaggedTilesEvent evt) { + listeners.forEach(listener -> listener.onFlaggedTilesEvent(evt)); + } + private void repaintTile(int n, int m) { repaint(n * tileSize, m * tileSize, (n + 1) * tileSize, (n + 1) * tileSize); } diff --git a/src/dev/kske/minesweeper/CustomDialog.java b/src/dev/kske/minesweeper/CustomDialog.java index 328cd22..69b3e27 100644 --- a/src/dev/kske/minesweeper/CustomDialog.java +++ b/src/dev/kske/minesweeper/CustomDialog.java @@ -39,47 +39,48 @@ public class CustomDialog extends JDialog { 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); + JLabel lblBoardWidthText = new JLabel("Board Width:"); + lblBoardWidthText.setFont(new Font("Tahoma", Font.PLAIN, 14)); + mcontentPanel.add(lblBoardWidthText); } + JLabel lblBoardWidth = new JLabel(""); + lblBoardWidth.setFont(new Font("Tahoma", Font.PLAIN, 14)); + mcontentPanel.add(lblBoardWidth); JSlider sliderBoardWidth = new JSlider(); + sliderBoardWidth.addChangeListener((evt) -> lblBoardWidth.setText(String.valueOf(sliderBoardWidth.getValue()))); 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); + JLabel lblBoardHeightText = new JLabel("Board Height:"); + lblBoardHeightText.setFont(new Font("Tahoma", Font.PLAIN, 14)); + mcontentPanel.add(lblBoardHeightText); } + JLabel lblBoardHeight = new JLabel(""); + lblBoardHeight.setFont(new Font("Tahoma", Font.PLAIN, 14)); + mcontentPanel.add(lblBoardHeight); JSlider sliderBoardHeight = new JSlider(); + sliderBoardHeight + .addChangeListener((evt) -> lblBoardHeight.setText(String.valueOf(sliderBoardHeight.getValue()))); 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); + JLabel lblNumberOfMinesText = new JLabel("Number of Mines:"); + lblNumberOfMinesText.setFont(new Font("Tahoma", Font.PLAIN, 14)); + mcontentPanel.add(lblNumberOfMinesText); } + JLabel lblNumMines = new JLabel(""); + lblNumMines.setFont(new Font("Tahoma", Font.PLAIN, 14)); + mcontentPanel.add(lblNumMines); JSlider sliderNumMines = new JSlider(); + sliderNumMines.addChangeListener((evt) -> lblNumMines.setText(String.valueOf(sliderNumMines.getValue()))); sliderNumMines.setValue(16); sliderNumMines.setMinimum(2); sliderNumMines.setMaximum(200); mcontentPanel.add(sliderNumMines); - { - JLabel label = new JLabel(""); - mcontentPanel.add(label); - } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));