示例#1
0
 public void actionPerformed(ActionEvent evt) // event handling
     {
   // Object source = evt.getSource(); //get who generates this event
   String arg = evt.getActionCommand();
   if (arg.equals("Register")) { // determine which button is clicked
     UName = UsernameField.getText(); // take actions
     PsWord = PasswordField.getText();
     PsWord1 = PasswordField1.getText();
     Acct = new Account(UName, PsWord, PsWord1);
     if (Acct.signUp())
       JOptionPane.showMessageDialog(
           null, "Account has been created!", "Confirmation", JOptionPane.INFORMATION_MESSAGE);
     else
       JOptionPane.showMessageDialog(
           null,
           "Account creation failed due to an invalid email address or unmatched passwords or the email address exists.",
           "Confirmation",
           JOptionPane.INFORMATION_MESSAGE);
   }
 }
  public UserEditing(int uid) {
    Container contentPane;
    JPanel comboPanel, okPanel;

    JButton okButton;
    JButton cancel;
    JTextField username;
    JTextField email;
    JTextField phone;
    String[] comboBoxItem = {"Trainees", "Trainers", "All Users"};

    // set the frame properties
    setSize(FRAME_WIDTH, FRAME_HEIGHT);
    setTitle("SSEM - User Editing");

    // set center
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Dimension screenSize = toolkit.getScreenSize();
    final int x = (screenSize.width - 300) / 2;
    final int y = (screenSize.height - 600) / 2;
    setLocation(x, y);

    contentPane = getContentPane();
    contentPane.setLayout(null);

    listID = Account.searchuserlistID(uid);

    // name
    JLabel userLabel = new JLabel("Name:");
    userLabel.setBounds(10, 10, 80, 25);
    username = new JTextField(20);
    username.setBounds(100, 10, 160, 25);
    username.setText(Account.userlist.get(listID).getUserName());

    // email
    JLabel emailLabel = new JLabel("Email:");
    emailLabel.setBounds(10, 50, 80, 25);
    email = new JTextField(20);
    email.setBounds(100, 50, 160, 25);
    email.setText(Account.userlist.get(listID).getUserEmail());

    // phone
    JLabel phoneLabel = new JLabel("Phone:");
    phoneLabel.setBounds(10, 90, 80, 25);
    phone = new JTextField(20);
    phone.setBounds(100, 90, 160, 25);
    phone.setText(Account.userlist.get(listID).getUserPhone());

    // create and place the OK button
    okButton = new JButton("OK");
    okButton.setBounds(10, 170, 80, 25);

    // create and place the Cancel button
    cancel = new JButton("Cancel");
    cancel.setBounds(100, 170, 80, 25);

    contentPane.add(userLabel);
    contentPane.add(username);
    contentPane.add(emailLabel);
    contentPane.add(email);
    contentPane.add(phoneLabel);
    contentPane.add(phone);
    contentPane.add(okButton);
    contentPane.add(cancel);

    ///// listener/////////////////////////////////////////////////
    // name////on ENTER key switch to password
    username.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (checkname(username.getText())) email.requestFocusInWindow();
          }
        });

    // email////on ENTER key switch to phone
    email.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (checkemail(email.getText())) phone.requestFocusInWindow();
          }
        });

    // phone////on ENTER key switch to  birth
    phone.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (checkphone(phone.getText())) okButton.doClick();
          }
        });

    // register 'Exit upon closing' as a default close operation
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });

    okButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (checkname(username.getText())
                && checkphone(phone.getText())
                && checkphone(phone.getText())) {
              if (JOptionPane.showConfirmDialog(
                      null, "Edit information ??", " ", JOptionPane.YES_NO_OPTION)
                  == JOptionPane.YES_OPTION) {
                Account.userlist.get(listID).setUserName(username.getText());
                Account.userlist.get(listID).setUserEmail(email.getText());
                Account.userlist.get(UserEditing.listID).setUserPhone(phone.getText());
                Account.listAll();
                dispose();
              } else {
                JOptionPane.showMessageDialog(
                    null, "Action Cancelled & SYSTEM END.", " ", JOptionPane.WARNING_MESSAGE);
              }
            }
          }
        });
  }