Browse Source

refactoring: refactored variable names

master
Ozan-Can Ekinci 2 years ago
parent
commit
660a2bad48
  1. 4
      src/main/java/Gui/ActionHandler.java
  2. 36
      src/main/java/Gui/GameGui.java

4
src/main/java/Gui/ActionHandler.java

@ -19,14 +19,14 @@ public class ActionHandler implements ActionListener {
if (e.getSource() == GameGui.RestartBtn) {
GameGui.questionNr = 0;
GameGui.LosingPanel.setVisible(false);
GameGui.counter = 1;
GameGui.currentQuestion = 1;
restartGame.startGame();
}
if (e.getSource() == GameGui.RestartBtn1) {
GameGui.questionNr = 0;
GameGui.WinningPanel.setVisible(false);
GameGui.counter = 1;
GameGui.currentQuestion = 1;
restartGame.startGame();
}

36
src/main/java/Gui/GameGui.java

@ -15,11 +15,11 @@ import game.runGame;
public class GameGui implements GameGuiInterface {
public static JPanel MainPanel, ButtonPanel, headingPanel, WinningPanel, LosingPanel;
public static JLabel Headline, QuestionLabel, WinningLabel, LosingLabel, ShowQuestionNr, HighScoreLabel;
public static JPanel MainPanel, ButtonPanel, HeadingPanel, WinningPanel, LosingPanel;
public static JLabel HeadlineLabel, QuestionLabel, WinningLabel, LosingLabel, CurrentQuestionNrLabel, HighScoreLabel;
public static JButton AnswersBtn1, AnswersBtn2, AnswersBtn3, AnswersBtn4, RestartBtn, RestartBtn1, ClosingBtn;
public static int questionNr = 0;
public static int counter = 1;
public static int currentQuestion = 1;
public static int highScore = 0;
GridLayout grid;
GridBagConstraints gbc;
@ -37,10 +37,10 @@ public class GameGui implements GameGuiInterface {
public void CreatePanel() {
MainPanel = new JPanel();
ButtonPanel = new JPanel();
headingPanel = new JPanel();
HeadingPanel = new JPanel();
grid = new GridLayout(2, 1);
grid.setVgap(150);
headingPanel.setLayout(grid);
HeadingPanel.setLayout(grid);
gui.Frame.add(MainPanel);
}
@ -62,7 +62,7 @@ public class GameGui implements GameGuiInterface {
LosingPanel = new JPanel();
LosingPanel.setLayout(new GridBagLayout());
LosingLabel = new JLabel();
LosingLabel.setText("Du hast Frage " + (counter - 1) + " falsch beantwortet");
LosingLabel.setText("Du hast Frage " + (currentQuestion - 1) + " falsch beantwortet");
LosingLabel.setVerticalAlignment(JLabel.CENTER);
LosingLabel.setHorizontalAlignment(JLabel.CENTER);
LosingLabel.setFont(new Font("Serif", Font.BOLD, 28));
@ -92,7 +92,7 @@ public class GameGui implements GameGuiInterface {
WinningPanel = new JPanel();
WinningPanel.setLayout(new GridBagLayout());
WinningLabel = new JLabel("Du hast Gewonnen!");
WinningLabel = new JLabel("Du hast Gewonnen");
WinningLabel.setVerticalAlignment(JLabel.CENTER);
WinningLabel.setHorizontalAlignment(JLabel.CENTER);
WinningLabel.setFont(new Font("Serif", Font.BOLD, 28));
@ -109,21 +109,21 @@ public class GameGui implements GameGuiInterface {
public void createShowQuestion(int i) {
int numLines = runGame.CountFileLines("QandA/Money.txt");
String[] arrMoney = runGame.readFile("QandA/Money.txt", numLines);
String questionText = "Frage " + counter + ": " + arrMoney[i - 1] + " Euro";
counter++;
String questionText = "Frage " + currentQuestion + ": " + arrMoney[i - 1] + " Euro";
currentQuestion++;
ShowQuestionNr.setText(questionText);
MainPanel.add(ShowQuestionNr);
CurrentQuestionNrLabel.setText(questionText);
MainPanel.add(CurrentQuestionNrLabel);
}
@Override
public void createHeadline() {
Headline = new JLabel("Wer wird Millionaer?");
headingPanel.add(Headline);
ShowQuestionNr = new JLabel();
MainPanel.add(headingPanel);
Headline.setHorizontalAlignment(JLabel.CENTER);
Headline.setFont(new Font("Serif", Font.BOLD, 28));
HeadlineLabel = new JLabel("Wer wird Millionaer");
HeadingPanel.add(HeadlineLabel);
CurrentQuestionNrLabel = new JLabel();
MainPanel.add(HeadingPanel);
HeadlineLabel.setHorizontalAlignment(JLabel.CENTER);
HeadlineLabel.setFont(new Font("Serif", Font.BOLD, 28));
}
@Override
@ -133,7 +133,7 @@ public class GameGui implements GameGuiInterface {
QuestionLabel.setHorizontalAlignment(JLabel.CENTER);
QuestionLabel.setVerticalAlignment(JLabel.NORTH);
QuestionLabel.setFont(new Font("Serif", Font.BOLD, 20));
headingPanel.add(QuestionLabel);
HeadingPanel.add(QuestionLabel);
}
@Override

Loading…
Cancel
Save