Guest User

Untitled

a guest
Dec 20th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.02 KB | None | 0 0
  1. package AuiAs2.View;
  2.  
  3. import AuiAs2.MathsGame;
  4. import AuiAs2.MigJPanel;
  5. import AuiAs2.ScreenInterface;
  6.  
  7. import javax.swing.*;
  8. import java.awt.event.ActionListener;
  9. import java.awt.font.TextAttribute;
  10. import java.util.ArrayList;
  11. import java.util.Map;
  12.  
  13. /**
  14.  * Class for difficulty selection screen
  15.  */
  16. public class DiffView extends MigJPanel implements ScreenInterface {
  17.     MigJPanel panDiff;
  18.     JLabel labAppTitle;
  19.     Map titleAttributes;
  20.     JLabel labGameInfo;
  21.     JLabel labDiffHead;
  22.     ButtonGroup btgrpDiff;
  23.     ArrayList<JRadioButton> listRadButton;
  24.     JLabel labMouseOver;
  25.     JButton butNewGame;
  26.  
  27.     public DiffView() {
  28.         panDiff = new MigJPanel();
  29.         labAppTitle = new JLabel("Maths Game");
  30.         titleAttributes = fontTitle.getAttributes(); //used for underline on title
  31.         titleAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
  32.         labAppTitle.setFont(fontTitle.deriveFont(titleAttributes));
  33.         panDiff.add(labAppTitle, "align 50%, shrink 2, push x, wrap");
  34.         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>");
  35.         panDiff.add(labGameInfo, "align 50%, push 2 2, wrap");
  36.         labDiffHead = new JLabel("Choose Difficulty:");
  37.         labDiffHead.setFont(fontHeading);
  38.         panDiff.add(labDiffHead, "align 50%, shrink 2, wrap");
  39.         btgrpDiff = new ButtonGroup();
  40.         listRadButton = new ArrayList<JRadioButton>();
  41.         for (Difficulty diff : Difficulty.values()) {
  42.             JRadioButton radDiff = new JRadioButton(diff.name);
  43.             radDiff.setActionCommand(diff.name);
  44.             System.out.println(diff.name + " created.");
  45.             System.out.println(radDiff.getActionCommand());
  46.             listRadButton.add(radDiff);
  47.             btgrpDiff.add(radDiff);
  48.             panDiff.add(radDiff, "align 50%, shrink 2, wrap");
  49.         }
  50.         btgrpDiff.setSelected(listRadButton.get(Difficulty.MEDIUM.ordinal()).getModel(), true);
  51.         labMouseOver = new JLabel("Mouse over a difficulty for further explanation of each.");
  52.         panDiff.add(labMouseOver, "align 50%, shrink 2, wrap");
  53.         butNewGame = new JButton("New Game");
  54.         panDiff.add(butNewGame, "align 50%, grow x, wrap"); //fix shrink
  55.         //butNewGame.addActionListener(e -> MathsGame.switchToGame(btgrpDiff.getSelection()));
  56.         //butNewGame.addActionListener(e -> MathsGame.switchToGame());
  57.         add(panDiff, "push x, push y, align 50% 50%");
  58.     }
  59.  
  60.     public String getSelectedDiff() {
  61.         return btgrpDiff.getSelection().getActionCommand();
  62.     }
  63.  
  64.     public void addNewGameListener(ActionListener listenNewGame) {
  65.         butNewGame.addActionListener(listenNewGame);
  66.     }
  67.  
  68.     /*
  69.     public void switchToGame() {
  70.         //MathsGame.setLayCard(panContainer, "New Game");
  71.     }
  72.  
  73.     public void switchToGame(ButtonModel selectedDiff) {
  74.         MathsGame.switchToGame(selectedDiff);
  75.     }
  76.     */
  77. }
Advertisement
Add Comment
Please, Sign In to add comment