Browse Source

refactoring: adjusted layout of classes

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

43
src/main/java/Gui/GameGui.java

@ -13,17 +13,16 @@ import javax.swing.JPanel;
import game.loadNextQuestion; import game.loadNextQuestion;
import game.runGame; 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 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 @Override
public void createGui() { public void createGui() {
@ -35,11 +34,11 @@ GridBagConstraints gbc;
} }
@Override @Override
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);
@ -68,9 +67,9 @@ GridBagConstraints gbc;
LosingLabel.setHorizontalAlignment(JLabel.CENTER); LosingLabel.setHorizontalAlignment(JLabel.CENTER);
LosingLabel.setFont(new Font("Serif", Font.BOLD, 28)); 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()); RestartBtn.addActionListener(new ActionHandler());
ClosingBtn.addActionListener(new ActionHandler()); ClosingBtn.addActionListener(new ActionHandler());
gui.Frame.add(LosingPanel); gui.Frame.add(LosingPanel);
@ -98,9 +97,9 @@ GridBagConstraints gbc;
WinningLabel.setHorizontalAlignment(JLabel.CENTER); WinningLabel.setHorizontalAlignment(JLabel.CENTER);
WinningLabel.setFont(new Font("Serif", Font.BOLD, 28)); 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()); RestartBtn1.addActionListener(new ActionHandler());
ClosingBtn.addActionListener(new ActionHandler()); ClosingBtn.addActionListener(new ActionHandler());
gui.Frame.add(WinningPanel); gui.Frame.add(WinningPanel);
@ -143,7 +142,7 @@ GridBagConstraints gbc;
gbc = new GridBagConstraints(); gbc = new GridBagConstraints();
gbc.gridwidth = 1; gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10,10,10,10);
gbc.insets = new Insets(10, 10, 10, 10);
gbc.ipadx = 300; gbc.ipadx = 300;
gbc.ipady = 100; gbc.ipady = 100;
} }
@ -154,24 +153,24 @@ GridBagConstraints gbc;
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = 0; gbc.gridy = 0;
AnswersBtn1.addActionListener(new loadNextQuestion()); AnswersBtn1.addActionListener(new loadNextQuestion());
ButtonPanel.add(AnswersBtn1,gbc);
ButtonPanel.add(AnswersBtn1, gbc);
gbc.gridx = 1; gbc.gridx = 1;
gbc.gridy = 0; gbc.gridy = 0;
AnswersBtn2 = new JButton(); AnswersBtn2 = new JButton();
AnswersBtn2.addActionListener(new loadNextQuestion()); AnswersBtn2.addActionListener(new loadNextQuestion());
ButtonPanel.add(AnswersBtn2,gbc);
ButtonPanel.add(AnswersBtn2, gbc);
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = 1; gbc.gridy = 1;
AnswersBtn3 = new JButton(); AnswersBtn3 = new JButton();
AnswersBtn3.addActionListener(new loadNextQuestion()); AnswersBtn3.addActionListener(new loadNextQuestion());
ButtonPanel.add(AnswersBtn3,gbc);
ButtonPanel.add(AnswersBtn3, gbc);
gbc.gridx = 1; gbc.gridx = 1;
gbc.gridy = 1; gbc.gridy = 1;
AnswersBtn4 = new JButton(); AnswersBtn4 = new JButton();
ButtonPanel.add(AnswersBtn4,gbc);
ButtonPanel.add(AnswersBtn4, gbc);
ButtonPanel.setVisible(true); ButtonPanel.setVisible(true);
AnswersBtn4.addActionListener(new loadNextQuestion()); AnswersBtn4.addActionListener(new loadNextQuestion());
MainPanel.add(ButtonPanel); MainPanel.add(ButtonPanel);

5
src/main/java/game/loadNextQuestion.java

@ -21,7 +21,6 @@ public class loadNextQuestion implements ActionListener {
} }
} }
else if (runGame.splitAns[4].equals("2")) { else if (runGame.splitAns[4].equals("2")) {
if (e.getSource() == GameGui.AnswersBtn2) { if (e.getSource() == GameGui.AnswersBtn2) {
loadQuestions(); loadQuestions();
@ -30,7 +29,6 @@ public class loadNextQuestion implements ActionListener {
} }
} }
else if (runGame.splitAns[4].equals("3")) { else if (runGame.splitAns[4].equals("3")) {
if (e.getSource() == GameGui.AnswersBtn3) { if (e.getSource() == GameGui.AnswersBtn3) {
loadQuestions(); loadQuestions();
@ -39,7 +37,6 @@ public class loadNextQuestion implements ActionListener {
} }
} }
else if (runGame.splitAns[4].equals("4")) { else if (runGame.splitAns[4].equals("4")) {
if (e.getSource() == GameGui.AnswersBtn4) { if (e.getSource() == GameGui.AnswersBtn4) {
loadQuestions(); loadQuestions();
@ -63,4 +60,4 @@ public class loadNextQuestion implements ActionListener {
gameStatus.highScore(); gameStatus.highScore();
} }
}
}
Loading…
Cancel
Save