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) { if (e.getSource() == GameGui.RestartBtn) {
GameGui.questionNr = 0; GameGui.questionNr = 0;
GameGui.LosingPanel.setVisible(false); GameGui.LosingPanel.setVisible(false);
GameGui.counter = 1;
GameGui.currentQuestion = 1;
restartGame.startGame(); restartGame.startGame();
} }
if (e.getSource() == GameGui.RestartBtn1) { if (e.getSource() == GameGui.RestartBtn1) {
GameGui.questionNr = 0; GameGui.questionNr = 0;
GameGui.WinningPanel.setVisible(false); GameGui.WinningPanel.setVisible(false);
GameGui.counter = 1;
GameGui.currentQuestion = 1;
restartGame.startGame(); restartGame.startGame();
} }

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

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

Loading…
Cancel
Save