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

Loading…
Cancel
Save