Browse Source

refactoring: adjusted layout of classes

master
Ozan-Can Ekinci 2 years ago
parent
commit
1c649cf3ee
  1. 63
      src/main/java/Gui/GameGui.java
  2. 77
      src/main/java/game/loadNextQuestion.java

63
src/main/java/Gui/GameGui.java

@ -13,17 +13,16 @@ import javax.swing.JPanel;
import game.loadNextQuestion;
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 JButton AnswersBtn1, AnswersBtn2, AnswersBtn3, AnswersBtn4, RestartBtn, RestartBtn1, ClosingBtn;
public static int questionNr = 0;
public static int counter = 1;
public static int highScore = 0;
GridLayout grid;
GridBagConstraints gbc;
public static JPanel MainPanel, ButtonPanel, headingPanel, WinningPanel, LosingPanel;
public static JLabel Headline, QuestionLabel, WinningLabel, LosingLabel, ShowQuestionNr, HighScoreLabel;
public static JButton AnswersBtn1, AnswersBtn2, AnswersBtn3, AnswersBtn4, RestartBtn, RestartBtn1, ClosingBtn;
public static int questionNr = 0;
public static int counter = 1;
public static int highScore = 0;
GridLayout grid;
GridBagConstraints gbc;
@Override
public void createGui() {
@ -35,11 +34,11 @@ GridBagConstraints gbc;
}
@Override
public void CreatePanel(){
public void CreatePanel() {
MainPanel = new JPanel();
ButtonPanel = new JPanel();
headingPanel = new JPanel();
grid = new GridLayout(2,1);
grid = new GridLayout(2, 1);
grid.setVgap(150);
headingPanel.setLayout(grid);
gui.Frame.add(MainPanel);
@ -52,12 +51,12 @@ GridBagConstraints gbc;
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.ipadx = 200;
gbc.ipady = 100;
gbc.insets = new Insets(20, 0, 0, 0);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.ipadx = 200;
gbc.ipady = 100;
gbc.insets = new Insets(20, 0, 0, 0);
RestartBtn = new JButton("Neustarten");
RestartBtn = new JButton("Neustarten");
ClosingBtn = new JButton("Schliessen");
LosingPanel = new JPanel();
@ -68,9 +67,9 @@ GridBagConstraints gbc;
LosingLabel.setHorizontalAlignment(JLabel.CENTER);
LosingLabel.setFont(new Font("Serif", Font.BOLD, 28));
LosingPanel.add(LosingLabel,gbc);
LosingPanel.add(RestartBtn,gbc);
LosingPanel.add(ClosingBtn,gbc);
LosingPanel.add(LosingLabel, gbc);
LosingPanel.add(RestartBtn, gbc);
LosingPanel.add(ClosingBtn, gbc);
RestartBtn.addActionListener(new ActionHandler());
ClosingBtn.addActionListener(new ActionHandler());
gui.Frame.add(LosingPanel);
@ -83,10 +82,10 @@ GridBagConstraints gbc;
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.ipadx = 200;
gbc.ipady = 100;
gbc.insets = new Insets(20, 0, 0, 0);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.ipadx = 200;
gbc.ipady = 100;
gbc.insets = new Insets(20, 0, 0, 0);
RestartBtn1 = new JButton("Nochmal Spielen");
ClosingBtn = new JButton("Schliessen");
@ -98,12 +97,12 @@ GridBagConstraints gbc;
WinningLabel.setHorizontalAlignment(JLabel.CENTER);
WinningLabel.setFont(new Font("Serif", Font.BOLD, 28));
WinningPanel.add(WinningLabel,gbc);
WinningPanel.add(RestartBtn1,gbc);
WinningPanel.add(ClosingBtn,gbc);
WinningPanel.add(WinningLabel, gbc);
WinningPanel.add(RestartBtn1, gbc);
WinningPanel.add(ClosingBtn, gbc);
RestartBtn1.addActionListener(new ActionHandler());
ClosingBtn.addActionListener(new ActionHandler());
gui.Frame.add(WinningPanel);
gui.Frame.add(WinningPanel);
}
@Override
@ -143,7 +142,7 @@ GridBagConstraints gbc;
gbc = new GridBagConstraints();
gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10,10,10,10);
gbc.insets = new Insets(10, 10, 10, 10);
gbc.ipadx = 300;
gbc.ipady = 100;
}
@ -154,24 +153,24 @@ GridBagConstraints gbc;
gbc.gridx = 0;
gbc.gridy = 0;
AnswersBtn1.addActionListener(new loadNextQuestion());
ButtonPanel.add(AnswersBtn1,gbc);
ButtonPanel.add(AnswersBtn1, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
AnswersBtn2 = new JButton();
AnswersBtn2.addActionListener(new loadNextQuestion());
ButtonPanel.add(AnswersBtn2,gbc);
ButtonPanel.add(AnswersBtn2, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
AnswersBtn3 = new JButton();
AnswersBtn3.addActionListener(new loadNextQuestion());
ButtonPanel.add(AnswersBtn3,gbc);
ButtonPanel.add(AnswersBtn3, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
AnswersBtn4 = new JButton();
ButtonPanel.add(AnswersBtn4,gbc);
ButtonPanel.add(AnswersBtn4, gbc);
ButtonPanel.setVisible(true);
AnswersBtn4.addActionListener(new loadNextQuestion());
MainPanel.add(ButtonPanel);

77
src/main/java/game/loadNextQuestion.java

@ -13,54 +13,51 @@ public class loadNextQuestion implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (runGame.splitAns[4].equals("1")) {
if (e.getSource() == GameGui.AnswersBtn1) {
loadQuestions();
} else {
wrongAnswer();
}
if (runGame.splitAns[4].equals("1")) {
if (e.getSource() == GameGui.AnswersBtn1) {
loadQuestions();
} else {
wrongAnswer();
}
}
else if (runGame.splitAns[4].equals("2")) {
if (e.getSource() == GameGui.AnswersBtn2) {
loadQuestions();
} else {
wrongAnswer();
}
}
else if (runGame.splitAns[4].equals("3")) {
if (e.getSource() == GameGui.AnswersBtn3) {
loadQuestions();
} else {
wrongAnswer();
}
else if (runGame.splitAns[4].equals("2")) {
if (e.getSource() == GameGui.AnswersBtn2) {
loadQuestions();
} else {
wrongAnswer();
}
}
else if (runGame.splitAns[4].equals("4")) {
if (e.getSource() == GameGui.AnswersBtn4) {
loadQuestions();
} else {
wrongAnswer();
}
else if (runGame.splitAns[4].equals("3")) {
if (e.getSource() == GameGui.AnswersBtn3) {
loadQuestions();
} else {
wrongAnswer();
}
}
public void loadQuestions() {
if (GameGui.questionNr != runGame.arrQuestions.length - 1) {
StartGame.run(GameGui.questionNr);
gameStatus.createShowQuestion(GameGui.questionNr);
} else {
gameStatus.createWinningPanel();
}
else if (runGame.splitAns[4].equals("4")) {
if (e.getSource() == GameGui.AnswersBtn4) {
loadQuestions();
} else {
wrongAnswer();
}
}
}
public void wrongAnswer() {
gameStatus.createLosingPanel();
gameStatus.highScore();
}
public void loadQuestions() {
if (GameGui.questionNr != runGame.arrQuestions.length - 1) {
StartGame.run(GameGui.questionNr);
gameStatus.createShowQuestion(GameGui.questionNr);
} else {
gameStatus.createWinningPanel();
}
}
public void wrongAnswer() {
gameStatus.createLosingPanel();
gameStatus.highScore();
}
}
Loading…
Cancel
Save