コード例 #1
0
  public AddNewUser() {
    super("Add New User", true, false, true, true);
    msg = new JOptionPane();
    rand = new RandomPassword();
    ec = new EasyCrypt();
    db = new ExecDb();
    AddNewUserLayout customLayout = new AddNewUserLayout();

    getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
    getContentPane().setLayout(customLayout);

    accType = new JComboBox();
    accType.addItem("Student");
    accType.addItem("Teacher");
    accType.addItem("Officer");
    getContentPane().add(accType);

    accTxt = new JTextField("");
    getContentPane().add(accTxt);

    label_1 = new JLabel("Add new user account", JLabel.CENTER);
    getContentPane().add(label_1);

    label_2 = new JLabel("Account Type : ");
    getContentPane().add(label_2);

    label_3 = new JLabel("Account ID : ");
    getContentPane().add(label_3);

    button_1 = new JButton("ADD");
    getContentPane().add(button_1);

    button_2 = new JButton("CLOSE");
    getContentPane().add(button_2);

    passTxt = new JTextField("");
    passTxt.setEditable(false);
    getContentPane().add(passTxt);

    label_4 = new JLabel("Random Password : ");
    getContentPane().add(label_4);

    setSize(getPreferredSize());
    accType.addItemListener(this);
    button_1.addActionListener(this);
    button_2.addActionListener(this);
  }
コード例 #2
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == button_1) // ADD
   {
     if (acc == 0) // student
     {
       secret = rand.generatePassword();
       sql =
           "insert into studentAccount(username,password)"
               + " values('"
               + accTxt.getText()
               + "','"
               + ec.encrypt(secret)
               + "')";
       db.execUpdate(sql);
     } else if (acc == 1) // teacher
     {
       secret = rand.generatePassword();
       sql =
           "insert into teacherAccount(username,password)"
               + " values('"
               + accTxt.getText()
               + "','"
               + ec.encrypt(secret)
               + "')";
       db.execUpdate(sql);
     } else if (acc == 2) // officer
     {
       secret = rand.generatePassword();
       sql =
           "insert into officerAccount(username,password)"
               + " values('"
               + accTxt.getText()
               + "','"
               + ec.encrypt(secret)
               + "')";
       db.execUpdate(sql);
     }
     passTxt.setText(secret);
     msg.showMessageDialog(null, "New Account Created!");
   } else if (e.getSource() == button_2) {
     setVisible(false);
     MainGui.m_AdUser.setSelected(false);
   }
   accTxt.setText("");
   passTxt.setText("");
 }