Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hilomocked;
- /**
- * Text generated by Simple GUI Extension for BlueJ
- */
- import java.awt.*;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- /**
- * GUI for the High Low Game.
- *
- * @author jdalbey
- * @version 2013.1.20
- */
- public class HiLoGUI extends JFrame implements java.util.Observer
- {
- private JButton button1;
- private JButton button2;
- private JLabel label1;
- private JLabel label2;
- private JTextField txtNumber;
- private JTextField txtBalance;
- private ActionListener controller;
- //Constructor
- public HiLoGUI(ActionListener controller)
- {
- this.controller = controller;
- this.setTitle("GUI_project");
- this.setSize(366, 225);
- //pane with null layout
- JPanel contentPane = new JPanel(null);
- contentPane.setPreferredSize(new Dimension(366, 225));
- contentPane.setBackground(new Color(192, 192, 192));
- button1 = new JButton();
- button1.setBounds(13, 90, 112, 34);
- button1.setBackground(new Color(214, 217, 223));
- button1.setForeground(new Color(0, 0, 0));
- button1.setEnabled(true);
- button1.setFont(new Font("DejaVu Sans", 0, 12));
- button1.setText("Guess High");
- button1.setActionCommand(AbstractGame.Guess.high.toString());
- button1.setVisible(true);
- //Set action for button click
- button1.addActionListener(controller);
- button2 = new JButton();
- button2.setBounds(14, 139, 110, 33);
- button2.setBackground(new Color(214, 217, 223));
- button2.setForeground(new Color(0, 0, 0));
- button2.setEnabled(true);
- button2.setFont(new Font("DejaVu Sans", 0, 12));
- button2.setText("Guess Low");
- button2.setActionCommand(AbstractGame.Guess.low.toString());
- button2.setVisible(true);
- //Set action for button click
- button2.addActionListener(controller);
- label1 = new JLabel();
- label1.setBounds(16, 31, 90, 35);
- label1.setBackground(new Color(214, 217, 223));
- label1.setForeground(new Color(0, 0, 0));
- label1.setEnabled(true);
- label1.setFont(new Font("DejaVu Sans", 0, 12));
- label1.setText("Number");
- label1.setVisible(true);
- label2 = new JLabel();
- label2.setBounds(177, 27, 87, 41);
- label2.setBackground(new Color(214, 217, 223));
- label2.setForeground(new Color(0, 0, 0));
- label2.setEnabled(true);
- label2.setFont(new Font("DejaVu Sans", 0, 12));
- label2.setText("Balance");
- label2.setVisible(true);
- txtNumber = new JTextField();
- txtNumber.setBounds(75, 30, 54, 32);
- txtNumber.setBackground(new Color(255, 255, 255));
- txtNumber.setForeground(new Color(0, 0, 0));
- txtNumber.setEnabled(true);
- txtNumber.setFont(new Font("DejaVu Sans", 0, 12));
- txtNumber.setText("0");
- txtNumber.setVisible(true);
- txtNumber.setEditable(false);
- txtNumber.setName("txtNumber");
- txtBalance = new JTextField();
- txtBalance.setBounds(247, 30, 71, 34);
- txtBalance.setBackground(new Color(255, 255, 255));
- txtBalance.setForeground(new Color(0, 0, 0));
- txtBalance.setEnabled(true);
- txtBalance.setFont(new Font("DejaVu Sans", 0, 12));
- txtBalance.setText("100");
- txtBalance.setVisible(true);
- txtBalance.setEditable(false);
- txtBalance.setName("txtBalance");
- //adding components to contentPane panel
- contentPane.add(button1);
- contentPane.add(button2);
- contentPane.add(label1);
- contentPane.add(label2);
- contentPane.add(txtNumber);
- contentPane.add(txtBalance);
- //adding panel to JFrame and seting of window position and close operation
- this.add(contentPane);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setLocationRelativeTo(null);
- this.pack();
- }
- /* Update the fields with current values */
- public void update(java.util.Observable obs, Object obj)
- {
- AbstractGame game = (AbstractGame) obs;
- txtNumber.setText("" + game.getCurrentNum());
- txtBalance.setText("" + game.getBalance());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement