Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package AuiAs2.View;
- import AuiAs2.MathsGame;
- import AuiAs2.MigJPanel;
- import AuiAs2.ScreenInterface;
- import javax.swing.*;
- import java.awt.event.ActionListener;
- import java.awt.font.TextAttribute;
- import java.util.ArrayList;
- import java.util.Map;
- /**
- * Class for difficulty selection screen
- */
- public class DiffView extends MigJPanel implements ScreenInterface {
- MigJPanel panDiff;
- JLabel labAppTitle;
- Map titleAttributes;
- JLabel labGameInfo;
- JLabel labDiffHead;
- ButtonGroup btgrpDiff;
- ArrayList<JRadioButton> listRadButton;
- JLabel labMouseOver;
- JButton butNewGame;
- public DiffView() {
- panDiff = new MigJPanel();
- labAppTitle = new JLabel("Maths Game");
- titleAttributes = fontTitle.getAttributes(); //used for underline on title
- titleAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
- labAppTitle.setFont(fontTitle.deriveFont(titleAttributes));
- panDiff.add(labAppTitle, "align 50%, shrink 2, push x, wrap");
- labGameInfo = new JLabel("<html>The game will display an equation which you must answer in 3 attempts.<br> Further attempts will be added for every 5 correct answers.</html>");
- panDiff.add(labGameInfo, "align 50%, push 2 2, wrap");
- labDiffHead = new JLabel("Choose Difficulty:");
- labDiffHead.setFont(fontHeading);
- panDiff.add(labDiffHead, "align 50%, shrink 2, wrap");
- btgrpDiff = new ButtonGroup();
- listRadButton = new ArrayList<JRadioButton>();
- for (Difficulty diff : Difficulty.values()) {
- JRadioButton radDiff = new JRadioButton(diff.name);
- radDiff.setActionCommand(diff.name);
- System.out.println(diff.name + " created.");
- System.out.println(radDiff.getActionCommand());
- listRadButton.add(radDiff);
- btgrpDiff.add(radDiff);
- panDiff.add(radDiff, "align 50%, shrink 2, wrap");
- }
- btgrpDiff.setSelected(listRadButton.get(Difficulty.MEDIUM.ordinal()).getModel(), true);
- labMouseOver = new JLabel("Mouse over a difficulty for further explanation of each.");
- panDiff.add(labMouseOver, "align 50%, shrink 2, wrap");
- butNewGame = new JButton("New Game");
- panDiff.add(butNewGame, "align 50%, grow x, wrap"); //fix shrink
- //butNewGame.addActionListener(e -> MathsGame.switchToGame(btgrpDiff.getSelection()));
- //butNewGame.addActionListener(e -> MathsGame.switchToGame());
- add(panDiff, "push x, push y, align 50% 50%");
- }
- public String getSelectedDiff() {
- return btgrpDiff.getSelection().getActionCommand();
- }
- public void addNewGameListener(ActionListener listenNewGame) {
- butNewGame.addActionListener(listenNewGame);
- }
- /*
- public void switchToGame() {
- //MathsGame.setLayCard(panContainer, "New Game");
- }
- public void switchToGame(ButtonModel selectedDiff) {
- MathsGame.switchToGame(selectedDiff);
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment