Ejemplo n.º 1
0
  void addButton_actionPerformed(ActionEvent e) {
    if (jTextFieldAccountname.getText().length() == 0) {
      JOptionPane.showMessageDialog(
          null, "Fill in the Account Name", "Error", JOptionPane.ERROR_MESSAGE);
      jTextFieldAccountname.requestFocus();
    } else if (jTextFieldFullname.getText().length() == 0) {
      JOptionPane.showMessageDialog(
          null, "Fill in the Full Name", "Error", JOptionPane.ERROR_MESSAGE);
      jTextFieldFullname.requestFocus();
    } else if ((String.valueOf(jPasswordField1.getPassword()))
            .equals(String.valueOf(jPasswordField2.getPassword()))
        == false) {

      JOptionPane.showMessageDialog(
          null, "Passwords don't match", "Error", JOptionPane.ERROR_MESSAGE);
      jPasswordField1.requestFocus();
    } else {
      usermodel.addUser(
          new User(
              jTextFieldAccountname.getText(),
              jTextFieldFullname.getText(),
              jPasswordField1.getPassword()));
      usermodel.fireTableDataChanged();
    }
  }
Ejemplo n.º 2
0
 private void jbInit() throws Exception {
   titledBorder1 =
       new TitledBorder(BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "New User");
   titledBorder2 =
       new TitledBorder(
           BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "User accounts");
   this.setLayout(borderLayout1);
   jPanelNewUser.setBorder(titledBorder1);
   jPanelNewUser.setLayout(gridBagLayout1);
   jLabel1.setText("Account name: ");
   jTextFieldAccountname.setColumns(10);
   jLabel2.setText("Password: "******"Repeat Password: "******"Full name: ");
   jTextFieldFullname.setColumns(20);
   addButton.setText("Add");
   addButton.addActionListener(
       new charva.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           addButton_actionPerformed(e);
         }
       });
   jPanel1.setLayout(gridBagLayout2);
   deleteButton.setText("Delete");
   deleteButton.addActionListener(
       new charva.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           deleteButton_actionPerformed(e);
         }
       });
   jPanel1.setBorder(titledBorder2);
   this.add(jPanelNewUser, BorderLayout.NORTH);
   jPanelNewUser.add(
       jLabel1,
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jTextFieldAccountname,
       new GridBagConstraints(
           1,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jLabel4,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jTextFieldFullname,
       new GridBagConstraints(
           1,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jLabel2,
       new GridBagConstraints(
           0,
           2,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jPasswordField1,
       new GridBagConstraints(
           1,
           2,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jLabel3,
       new GridBagConstraints(
           0,
           3,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jPasswordField2,
       new GridBagConstraints(
           1,
           3,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       addButton,
       new GridBagConstraints(
           0,
           4,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   this.add(jPanel1, BorderLayout.CENTER);
   jPanel1.add(
       jPanelUsers,
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           100.0,
           100.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanel1.add(
       deleteButton,
       new GridBagConstraints(
           1,
           0,
           1,
           1,
           10.0,
           10.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
 }