Advertisement
Guest User

Untitled

a guest
Mar 7th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. // Submit Button Listener
  2. submitButton.addActionListener(new ActionListener(){
  3. public void actionPerformed(ActionEvent ae){
  4. boolean notDuplicated = false;
  5.  
  6. String id = studentIDField.getText();
  7. String username = userNameField.getText();
  8. String password = passwordField.getText();
  9.  
  10. boolean idValid = id.matches("\\d{5,6}");
  11. boolean usernameValid = username.matches("[A-Za-z][A-Za-z0-9]*@[A-Za-z][A-Za-z0-9]*\\.(com|edu|org)");
  12. boolean passwordValid = password.matches("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[~!#$])[A-Za-z0-9~!#$]{8,}$");
  13.  
  14. for (Student student : studentsList) {
  15. if (username.equals(student.getUsername())) {
  16. notDuplicated = true;
  17. }
  18. }
  19.  
  20. if (notDuplicated) {
  21. JOptionPane.showMessageDialog(rootPane, "Username already taken!");
  22. userNameField.setText("");
  23. }
  24.  
  25. if (!idValid) {
  26. JOptionPane.showMessageDialog(rootPane, "Please enter a valid user ID!");
  27. studentIDField.setText("");
  28. }
  29.  
  30. if (!usernameValid) {
  31. JOptionPane.showMessageDialog(rootPane, "Please enter a valid username!");
  32. userNameField.setText("");
  33. }
  34.  
  35. if (!passwordValid) {
  36. JOptionPane.showMessageDialog(rootPane, "Please enter a valid password!");;
  37. passwordField.setText("");
  38. }
  39.  
  40. if (notDuplicated == false && idValid == true && usernameValid == true && passwordValid == true) {
  41. for (Student student : studentsList) {
  42. if (id == student.getId()) {
  43. student.setUsername(username);
  44. student.setPassword(password);
  45. }
  46. }
  47. JOptionPane.showMessageDialog(rootPane, "Student account added!");
  48. studentIDField.setText("");
  49. userNameField.setText("");
  50. passwordField.setText("");
  51. }
  52. }
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement