Browse Source

refactoring: extract Methods for Interface

master
Leon Montag 2 years ago
parent
commit
2e2d7fb427
  1. 8
      src/main/java/Gui/GameGui.java
  2. 17
      src/main/java/Gui/GameGuiInterface.java
  3. 2
      src/main/java/Gui/StartGameGui.java

8
src/main/java/Gui/GameGui.java

@ -11,7 +11,7 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
public class GameGui {
public class GameGui implements GameGuiInterface {
public static JPanel MainPanel, ButtonPanel, headingPanel;
public static JLabel Headline,QuestionLabel;
@ -20,6 +20,7 @@ public static int questionNr = 0;
GridLayout grid;
GridBagConstraints gbc;
@Override
public void createGui() {
CreatePanel();
createHeadline();
@ -28,6 +29,7 @@ GridBagConstraints gbc;
createButtons();
}
@Override
public void CreatePanel(){
MainPanel = new JPanel();
ButtonPanel = new JPanel();
@ -37,6 +39,7 @@ GridBagConstraints gbc;
headingPanel.setLayout(grid);
gui.Frame.add(MainPanel);
}
@Override
public void createHeadline() {
Headline = new JLabel("Wer wird Millionär?");
headingPanel.add(Headline);
@ -44,6 +47,7 @@ GridBagConstraints gbc;
Headline.setHorizontalAlignment(JLabel.CENTER);
Headline.setFont(new Font("Serif", Font.BOLD, 28));
}
@Override
public void createQuestionLabel() {
QuestionLabel = new JLabel("Questions");
MainPanel.add(QuestionLabel);
@ -51,6 +55,7 @@ GridBagConstraints gbc;
QuestionLabel.setVerticalAlignment(JLabel.NORTH);
headingPanel.add(QuestionLabel);
}
@Override
public void createLayout() {
ButtonPanel.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
@ -61,6 +66,7 @@ GridBagConstraints gbc;
gbc.ipady = 100;
}
@Override
public void createButtons() {
AnswersBtn1 = new JButton();
gbc.gridx = 0;

17
src/main/java/Gui/GameGuiInterface.java

@ -0,0 +1,17 @@
package Gui;
public interface GameGuiInterface {
void createGui();
void CreatePanel();
void createHeadline();
void createQuestionLabel();
void createLayout();
void createButtons();
}

2
src/main/java/Gui/StartGameGui.java

@ -14,7 +14,7 @@ public class StartGameGui implements ActionListener {
startGame();
}
public void startGame() {
GameGui Gui = new GameGui();
GameGuiInterface Gui = new GameGui();
Gui.createGui();
runGame rungame = new runGame();

Loading…
Cancel
Save