Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 3.64 KB | None | 0 0
  1. package highlowgame;
  2.  
  3. import java.awt.Color;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.ActionEvent;
  6. import javax.swing.ButtonGroup;
  7. import javax.swing.JFrame;
  8. import javax.swing.JButton;
  9. import javax.swing.JPanel;
  10. import javax.swing.JRadioButton;
  11. import javax.swing.JComboBox;
  12. /**
  13.  *
  14.  * @author Patrick
  15.  */
  16. public class Main
  17.     {
  18.    static JPanel panel = new JPanel();
  19.    static JFrame frame = new JFrame();
  20.    static int dieTotal = HighLowDiceFace.redDiceFace +
  21.              HighLowDiceFace.whiteDiceFace;
  22.  
  23.     public static void main (String[] args)
  24.       {
  25.         //Basic frame setup
  26.        
  27.         final int FRAME_WIDTH = 800;
  28.         final int FRAME_HEIGHT = 600;
  29.         // Frame Attributes
  30.         frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
  31.         frame.setTitle("High Low Game");
  32.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33.         frame.setResizable(false);
  34.         //Panel attrib.
  35.         panel.setSize(800, 150);
  36.         panel.setLocation(0, 480);
  37.        // panel.setBackground(Color.red);
  38.         controls();
  39.         panel.setVisible(true);
  40.         frame.setVisible(true);
  41.        
  42.  
  43.     }
  44.  
  45.     public static void controls()
  46.     {
  47.         //Button setup
  48.         JButton roll = new  JButton("Roll");
  49.         class ButtonListener implements ActionListener
  50.         {
  51.             public void actionPerformed(ActionEvent e)
  52.             {
  53.             HighLowDice.rollRedDice();
  54.             HighLowDice.rollWhiteDice();
  55.             Main.frame.repaint();
  56.             System.out.println(GameLogic.target);
  57.             System.out.println(Main.dieTotal);
  58.             }
  59.  
  60.         }
  61.         roll.addActionListener(new ButtonListener());
  62.         panel.add(roll);
  63.  
  64.         //Radio button setup - These buttons control the win condition
  65.         JRadioButton highButton = new JRadioButton("High");
  66.         highButton.setActionCommand("high");
  67.         highButton.addActionListener(new RadioListener() );
  68.         JRadioButton sevenButton = new JRadioButton("Seven");
  69.         sevenButton.setActionCommand("seven");
  70.         sevenButton.addActionListener(new RadioListener() );
  71.         JRadioButton lowButton = new JRadioButton("Low");
  72.         lowButton.setActionCommand("low");
  73.         lowButton.addActionListener(new RadioListener() );
  74.        
  75.         class RadioListener implements ActionListener
  76.         {
  77.         //attempt to change static int target in class GameLogic
  78.             public void actionPerformed (ActionEvent e)
  79.             {
  80.                 if (e.getActionCommand().equals("high")){
  81.                     GameLogic.target = 8;}
  82.  
  83.                 else if (e.getActionCommand().equals("seven")){
  84.                     GameLogic.target = 7;}
  85.  
  86.                 else if(e.getActionCommand().equals("low")){
  87.                     GameLogic.target = 6;}
  88.                
  89.                
  90.             }
  91.            
  92.         }
  93.  
  94.  
  95.         //Creation of buttonGroup
  96.         ButtonGroup radioGroup = new ButtonGroup();
  97.         radioGroup.add(highButton);
  98.         radioGroup.add(sevenButton);
  99.         radioGroup.add(lowButton);
  100.         //add radio buttons to panel
  101.         panel.add(highButton);
  102.         panel.add(sevenButton);
  103.         panel.add(lowButton);
  104.         //setup comboboxes
  105.         JComboBox stakeSelect = new JComboBox();
  106.         stakeSelect.addItem("£1");
  107.         stakeSelect.addItem("£5");
  108.         stakeSelect.addItem("£10");
  109.        //Add stakeSelect to panel
  110.        panel.add(stakeSelect);
  111.        frame.add(panel);
  112.  
  113.         //Add Components to frame
  114.        HighLowDiceFace paintComponent = new HighLowDiceFace();
  115.        frame.add(paintComponent);
  116.  
  117.        
  118.  
  119.      }
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement