Example #1
0
  /** Constructor for allocating memory and simple initializing. */
  public GameBoard() {
    dealerPanel = new JPanel();
    playerPanel = new JPanel();
    controlPanel = new JPanel();
    money = new JLabel();
    record = new JLabel();
    inputImage = new JLabel(new ImageIcon("res/INPUT.gif"));
    moneyLabel = new JLabel(new ImageIcon("res/MONEY.gif"));
    betLabel = new JLabel(new ImageIcon("res/MAKE_YOUR_BET.gif"));
    recordLabel = new JLabel(new ImageIcon("res/BEST_SCORE.gif"));
    betButton = new JButton(new ImageIcon("res/BET.gif"));
    resultButton = new JButton(new ImageIcon("res/RESULT.gif"));
    betInput = new JTextField();

    try {
      recordReader = new BufferedReader(new FileReader("res/record"));
      bestScore = Integer.parseInt(recordReader.readLine());
      recordReader.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    inputImage.setLayout(new BorderLayout());
    controlPanel.setLayout(new FlowLayout());

    betInput.setHorizontalAlignment(JTextField.CENTER);
    betButton.setBorder(BorderFactory.createEmptyBorder());
    betButton.setContentAreaFilled(false);
    resultButton.setBorder(BorderFactory.createEmptyBorder());
    resultButton.setContentAreaFilled(false);
    resultButton.setEnabled(false);
    betButton.addMouseListener(new BetListener());
    resultButton.addMouseListener(new ResultListener());
    betInput.setOpaque(false);
    betInput.setBorder(BorderFactory.createEmptyBorder());
    money.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 30));
    record.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 30));
    setOpaque(false);

    initGame();
    initRound();
  }
  /** Initialize the contents of the frame. */
  private void initialize() {
    frmSignIn = new JFrame("Login");
    frmSignIn.setTitle("Sign in");
    frmSignIn.setResizable(false);
    frmSignIn.setBounds(100, 100, 450, 357);
    frmSignIn.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmSignIn.setLocationRelativeTo(null);

    JLabel lblEmail = new JLabel("Email:");
    lblEmail.setBounds(73, 108, 56, 18);

    JLabel lblPassword = new JLabel("Password:"******"Show Password");
    chckbxShowPassword.setBounds(130, 176, 128, 23);
    frmSignIn.getContentPane().add(chckbxShowPassword);

    chckbxShowPassword.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              passwordField.setEchoChar((char) 0);
            } else {
              passwordField.setEchoChar(a);
            }
          }
        });

    JButton btnNewButton = new JButton("Sign in");
    btnNewButton.setBounds(325, 106, 72, 62);
    btnNewButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            username = textField.getText();
            String password = String.valueOf(passwordField.getPassword()); // getText()
            // is
            // deprecated;
            // changed
            // to
            // getPassword()
            // password.toLowerCase();  Do we want case sensitive email?
            /*
             * SHA implementation to validate password
             */

            VaultController v = new VaultController();
            int result = 0;
            try {
              result = v.loginCheck(username, password);
            } catch (NoSuchAlgorithmException e1) {

              e1.printStackTrace();
            }
            if (result == 1) {
              failedattempt = 0;
              frmSignIn.dispose();

            } else {
              txtWarning.setText("The Email and/or Password is incorrect. Please try again.");
              failedattempt++;
            }
            // TODO migrate failcheck to Vault controller!
            if (failedattempt > 1 && failedattempt < 5) {
              try {
                VaultController.Send(
                    "sentineldatavault",
                    "SENTINELDATA",
                    username,
                    "Security Warning",
                    "Dear user,\n\nYou have multiple failed login attempts for your account.\n"
                        + "If it is not you, please change your password immediately.\n\n"
                        + "Sincerely,\nSentinel Data Vault Team");
              } catch (AddressException e1) {
                e1.printStackTrace();
              } catch (MessagingException e1) {
                e1.printStackTrace();
              }
            } else if (failedattempt == 5) {
              DatabaseManager d = new DatabaseManager("vault_database");
              User u = d.retrieveUserFromDatabase(username);
              d.deleteAllEntriesFromDatabase(u);
              d.deleteUserFromDatabase(u);
              try {
                JOptionPane.showMessageDialog(
                    null,
                    "Your account data has been deleted due to multiple failed login attempts");
                VaultController.Send(
                    "sentineldatavault",
                    "SENTINELDATA",
                    username,
                    "Security Warning",
                    "Dear user,\n\nWe have deleted your account.\n"
                        + "Have a nice day.\n\n"
                        + "Sincerely,\nSentinel Data Vault Team");
              } catch (AddressException e1) {
                e1.printStackTrace();
              } catch (MessagingException e1) {
                e1.printStackTrace();
              }
            }
          }
        });
    frmSignIn.getContentPane().setLayout(null);

    btnSignUp = new JButton("Create new account");
    btnSignUp.setToolTipText("Click here to create a new Sentinel Data Vault account!");
    btnSignUp.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            SignupView signup = new SignupView();
            signup.setVisible(true);
          }
        });
    btnSignUp.setBounds(57, 264, 158, 27);
    frmSignIn.getContentPane().add(btnSignUp);
    frmSignIn.getContentPane().add(btnNewButton);
    frmSignIn.getContentPane().add(lblPassword);
    frmSignIn.getContentPane().add(lblEmail);
    frmSignIn.getContentPane().add(textField);
    frmSignIn.getContentPane().add(passwordField);

    btnForgotPassword = new JButton("I forgot my password");
    btnForgotPassword.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            frmSignIn.setVisible(false);
            PasswordRecoveryView p = new PasswordRecoveryView(frmSignIn);
          }
        });
    btnForgotPassword.setToolTipText("Click here to reset your account password");
    btnForgotPassword.setBounds(227, 264, 170, 27);
    frmSignIn.getContentPane().add(btnForgotPassword);

    lblSentinelDataVault = new JLabel("Sentinel Data Vault");
    lblSentinelDataVault.setFont(new Font("Dialog", Font.PLAIN, 22));
    lblSentinelDataVault.setBounds(119, 33, 206, 27);
    frmSignIn.getContentPane().add(lblSentinelDataVault);

    txtWarning = new JTextField();
    txtWarning.setForeground(new Color(220, 20, 60));
    txtWarning.setBorder(null);
    txtWarning.setOpaque(false);
    txtWarning.setFocusable(false);
    txtWarning.setEditable(false);
    txtWarning.setFont(new Font("Tahoma", Font.ITALIC, 12));
    txtWarning.setBackground(SystemColor.window);
    txtWarning.setBounds(57, 196, 340, 26);
    frmSignIn.getContentPane().add(txtWarning);
    txtWarning.setColumns(10);

    frmSignIn
        .getContentPane()
        .setFocusTraversalPolicy(
            new FocusTraversalOnArray(new Component[] {textField, passwordField, btnNewButton}));
    frmSignIn.setFocusTraversalPolicy(
        new FocusTraversalOnArray(new Component[] {textField, passwordField, btnNewButton}));
  }
  void createGUI() {
    // create username field info
    Box fields = Box.createVerticalBox();
    fields.add(Box.createVerticalStrut(10));
    fields.setOpaque(false);

    JPanel userNameCont = new JPanel(new GridLayout(1, 2));
    JLabel usernameLabel = new JLabel("username ");
    usernameLabel.setFont(UIHelper.VER_12_BOLD);
    usernameLabel.setForeground(UIHelper.DARK_GREEN_COLOR);
    userNameCont.add(usernameLabel);

    username = new RoundedJTextField(10, UIHelper.TRANSPARENT_LIGHT_GREEN_COLOR);
    username.setOpaque(false);

    UIHelper.renderComponent(username, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);

    userNameCont.add(username);
    userNameCont.setOpaque(false);

    JPanel passwordCont = new JPanel(new GridLayout(1, 2));
    JLabel passwordLabel = new JLabel("password ");
    passwordLabel.setFont(UIHelper.VER_12_BOLD);
    passwordLabel.setForeground(UIHelper.DARK_GREEN_COLOR);
    passwordCont.add(passwordLabel);
    password = new RoundedJPasswordField(10, UIHelper.TRANSPARENT_LIGHT_GREEN_COLOR);
    UIHelper.renderComponent(password, UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR, false);

    passwordCont.add(password);
    passwordCont.setOpaque(false);

    fields.add(userNameCont);
    fields.add(Box.createVerticalStrut(10));
    fields.add(passwordCont);

    JPanel northPanel = new JPanel();
    northPanel.add(new JLabel(pleaseLogin, JLabel.RIGHT), BorderLayout.NORTH);
    northPanel.add(fields, BorderLayout.CENTER);

    JPanel southPanel = new JPanel(new GridLayout(4, 1));
    southPanel.setOpaque(false);

    JPanel buttonContainer = new JPanel(new GridLayout(1, 2));
    buttonContainer.setOpaque(false);

    createProfile = new JLabel(createProfileButton, JLabel.LEFT);
    createProfile.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent event) {
            createProfile.setIcon(createProfileButton);

            clearFields();

            confirmExitPanel.setVisible(false);

            menu.changeView(menu.getCreateProfileGUI());
          }

          public void mouseEntered(MouseEvent event) {
            createProfile.setIcon(createProfileButtonOver);
          }

          public void mouseExited(MouseEvent event) {
            createProfile.setIcon(createProfileButton);
          }
        });

    buttonContainer.add(createProfile);

    login = new JLabel(loginButton, JLabel.RIGHT);
    login.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent event) {
            login.setIcon(Authentication.this.loginButton);
            confirmExitPanel.setVisible(false);
            login();
          }

          public void mouseEntered(MouseEvent event) {
            login.setIcon(loginButtonOver);
          }

          public void mouseExited(MouseEvent event) {
            login.setIcon(Authentication.this.loginButton);
          }
        });

    Action loginAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            login();
          }
        };

    password.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "LOGIN");
    password.getActionMap().put("LOGIN", loginAction);
    username.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "LOGIN");
    username.getActionMap().put("LOGIN", loginAction);

    buttonContainer.add(login);

    southPanel.add(status);
    southPanel.add(buttonContainer);

    exit = new JLabel(exitButtonSml, JLabel.CENTER);
    exit.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent event) {
            exit.setIcon(exitButtonSml);
            confirmExitPanel.setVisible(true);
            confirmExitPanel.getParent().validate();
          }

          public void mouseEntered(MouseEvent event) {
            exit.setIcon(exitButtonSmlOver);
          }

          public void mouseExited(MouseEvent event) {
            exit.setIcon(exitButtonSml);
          }
        });

    JPanel exitCont = new JPanel(new GridLayout(1, 1));
    exitCont.setOpaque(false);

    exitCont.add(exit);

    southPanel.add(exitCont);

    southPanel.add(confirmExitPanel);

    northPanel.add(southPanel, BorderLayout.SOUTH);
    northPanel.setOpaque(false);

    add(northPanel, BorderLayout.CENTER);
  }
Example #4
0
  ShutdownFrame(CryoBay cb) {
    super("CryoBay Monitor");
    cryoB = cb;

    cmdClose =
        new JButton("Close") {
          public JToolTip createToolTip() {
            return new JToolTip();
          }
        };

    cmdClose.setToolTipText("Close program");

    cmdClose.addActionListener(this);
    addWindowListener(this);

    GridBagConstraints gbc = new GridBagConstraints();
    Border loweredbevel = BorderFactory.createLoweredBevelBorder();

    lblBStatus = new JLabel("Status: ");
    lblBHeater = new JLabel("Heater: ");
    lblBTemp = new JLabel("  Temp: ");
    lblBCli = new JLabel("   CLI: ");

    lblStatus = new JTextField(17);
    lblStatus.setEditable(false);
    lblStatus.setOpaque(true);
    lblStatus.setBorder(loweredbevel);

    lblHeater = new JTextField(17);
    lblHeater.setEditable(false);
    lblHeater.setOpaque(true);
    lblHeater.setBorder(loweredbevel);

    lblTemp = new JTextField(17);
    lblTemp.setEditable(false);
    lblTemp.setOpaque(true);
    lblTemp.setBorder(loweredbevel);

    lblCli = new JTextField(17);
    lblCli.setEditable(false);
    lblCli.setOpaque(true);
    lblCli.setBorder(loweredbevel);

    JPanel lblPanel = new JPanel();
    lblPanel.setLayout(new GridBagLayout());
    gbc.insets = new Insets(2, 5, 2, 5);
    setGbc(gbc, 0, 0, 1, 1);
    lblPanel.add(lblBStatus, gbc);
    setGbc(gbc, 0, 1, 1, 1);
    lblPanel.add(lblBHeater, gbc);
    setGbc(gbc, 0, 2, 1, 1);
    lblPanel.add(lblBTemp, gbc);
    setGbc(gbc, 0, 3, 1, 1);
    lblPanel.add(lblBCli, gbc);

    JPanel valPanel = new JPanel();
    valPanel.setLayout(new GridBagLayout());
    gbc.insets = new Insets(2, 5, 2, 5);
    setGbc(gbc, 0, 0, 1, 1);
    valPanel.add(lblStatus, gbc);
    setGbc(gbc, 0, 1, 1, 1);
    valPanel.add(lblHeater, gbc);
    setGbc(gbc, 0, 2, 1, 1);
    valPanel.add(lblTemp, gbc);
    setGbc(gbc, 0, 3, 1, 1);
    valPanel.add(lblCli, gbc);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    gbc.anchor = GridBagConstraints.CENTER;
    setGbc(gbc, 0, 5, 1, 1);
    buttonPanel.add(cmdClose, gbc);

    // finally, add the panels to the content pane
    getContentPane().setLayout(new GridBagLayout());
    gbc.insets = new Insets(10, 10, 10, 10);
    gbc.anchor = GridBagConstraints.CENTER;
    setGbc(gbc, 0, 0, 1, 4);
    getContentPane().add(lblPanel, gbc);
    setGbc(gbc, 1, 0, 1, 4);
    getContentPane().add(valPanel, gbc);
    setGbc(gbc, 0, 5, 0, 0);
    getContentPane().add(buttonPanel, gbc);

    setSize(300, 220);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation(screenSize.width / 2 - 300, screenSize.height / 2 - 220);
    setResizable(true);
  }