|
|
@ -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,31 +34,31 @@ 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); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void createLosingPanel() { |
|
|
|
MainPanel.setVisible(false); |
|
|
|
ButtonPanel.setVisible(false); |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
RestartBtn = new JButton("Neustarten"); |
|
|
|
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
|
|
gbc.ipadx = 200; |
|
|
|
gbc.ipady = 100; |
|
|
|
gbc.insets = new Insets(20, 0, 0, 0); |
|
|
|
|
|
|
|
RestartBtn = new JButton("Neustarten"); |
|
|
|
ClosingBtn = new JButton("Schliessen"); |
|
|
|
|
|
|
|
|
|
|
|
LosingPanel = new JPanel(); |
|
|
|
LosingPanel.setLayout(new GridBagLayout()); |
|
|
|
LosingLabel = new JLabel(); |
|
|
@ -67,10 +66,10 @@ GridBagConstraints gbc; |
|
|
|
LosingLabel.setVerticalAlignment(JLabel.CENTER); |
|
|
|
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); |
|
|
@ -80,39 +79,39 @@ GridBagConstraints gbc; |
|
|
|
public void createWinningPanel() { |
|
|
|
GameGui.MainPanel.setVisible(false); |
|
|
|
GameGui.ButtonPanel.setVisible(false); |
|
|
|
|
|
|
|
|
|
|
|
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"); |
|
|
|
|
|
|
|
|
|
|
|
WinningPanel = new JPanel(); |
|
|
|
WinningPanel.setLayout(new GridBagLayout()); |
|
|
|
WinningLabel = new JLabel("Du hast Gewonnen!"); |
|
|
|
WinningLabel.setVerticalAlignment(JLabel.CENTER); |
|
|
|
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 |
|
|
|
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++; |
|
|
|
|
|
|
|
|
|
|
|
ShowQuestionNr.setText(questionText); |
|
|
|
MainPanel.add(ShowQuestionNr); |
|
|
|
} |
|
|
@ -126,7 +125,7 @@ GridBagConstraints gbc; |
|
|
|
Headline.setHorizontalAlignment(JLabel.CENTER); |
|
|
|
Headline.setFont(new Font("Serif", Font.BOLD, 28)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void createQuestionLabel() { |
|
|
|
QuestionLabel = new JLabel("Questions"); |
|
|
@ -136,47 +135,47 @@ GridBagConstraints gbc; |
|
|
|
QuestionLabel.setFont(new Font("Serif", Font.BOLD, 20)); |
|
|
|
headingPanel.add(QuestionLabel); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void createLayout() { |
|
|
|
ButtonPanel.setLayout(new GridBagLayout()); |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void createButtons() { |
|
|
|
public void createButtons() { |
|
|
|
AnswersBtn1 = new JButton(); |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void highScore() { |
|
|
|
if (highScore < questionNr) { |
|
|
@ -185,5 +184,5 @@ GridBagConstraints gbc; |
|
|
|
HighScoreLabel = new JLabel("Dein Highscore ist: Frage " + highScore); |
|
|
|
LosingPanel.add(HighScoreLabel); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |