Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Move home button action listener to static block
Browse files Browse the repository at this point in the history
  • Loading branch information
powersagitar committed Jan 10, 2025
1 parent 9ba0492 commit 90e3d7e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
import mastermind.gui.scenes.Scene;

public class HomeButton {
private final static JButton homeButton;
private final static JPanel buttonPanel;
private final static JPanel buttonPanel = new JPanel();

static {
homeButton = new JButton("Home");
buttonPanel = new JPanel();
buttonPanel.add(homeButton);
}
final JButton homeButton = new JButton("Home");

public static void registerHomeHandlers() {
homeButton.addActionListener(event -> {
final JFrame gameModeSelector = Scene.createDefaultScene();
new GameModeSelector(gameModeSelector);
});

buttonPanel.add(homeButton);
}

public static void drawHomeButton(final JFrame frame) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public CodeBreaker(final JFrame frame, final MastermindAlgorithm algorithm) {

homeButton.drawHomeButton(frame);

homeButton.registerHomeHandlers();

registerGuessHandler();

refreshFrame();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public CodeBreakerSelector(final JFrame frame) {

homeButton.drawHomeButton(frame);

homeButton.registerHomeHandlers();

registerProceedHandler();

refreshFrame();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public CodeMaker(final JFrame frame) {

registerDeleteHandlers();

homeButton.registerHomeHandlers();

registerProceedHandlers();

refreshFrame();
Expand Down

0 comments on commit 90e3d7e

Please sign in to comment.