Guest User

Untitled

a guest
Mar 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. public class Login extends Fan2Fan {
  2.  
  3. public Login() {
  4. //Constructor
  5. }
  6. String ThisUser;
  7.  
  8. @Override
  9. public void start(Stage primaryStage) {
  10. Fan2Fan fanConn = new Fan2Fan();
  11. Login loginConn = new Login();
  12. Signup signupConn = new Signup();
  13. Account accountConn = new Account();
  14. Homepage homepageConn = new Homepage();
  15. Matches matchesConn = new Matches();
  16. Rovers roversConn = new Rovers();
  17. Cork corkConn = new Cork();
  18. Dundalk dundalkConn = new Dundalk();
  19. Payment payConn = new Payment();
  20. Update updateConn = new Update();
  21.  
  22. //Declare Login Page
  23. GridPane loginGrid = new GridPane();
  24. loginGrid.setAlignment(Pos.CENTER);
  25. loginGrid.setHgap(0);
  26. loginGrid.setVgap(10);
  27. //Login page title
  28. Text loginTitle = new Text("Please Login");
  29. loginTitle.setFont(Font.font("Tahoma", FontWeight.BOLD, 20));
  30. loginGrid.add(loginTitle, 0, 0, 5, 1);
  31. //Login UserName Details
  32. Label userNameLabel = new Label("User Name: ");
  33. loginGrid.add(userNameLabel, 0, 1);
  34. TextField userNameText = new TextField();
  35. userNameText.setPrefWidth(270);
  36. loginGrid.add(userNameText, 0, 2);
  37. ThisUser = userNameText.getText();
  38. //Login Password Details
  39. Label userPasswordLabel = new Label("Password: ");
  40. loginGrid.add(userPasswordLabel, 0, 4);
  41. PasswordField userPasswordText = new PasswordField();
  42. Label accountUserPassLabel = new Label();
  43. Tooltip tipPassword = new Tooltip();
  44. tipPassword.setText("Password is case sensitive");
  45. userPasswordText.setTooltip(tipPassword);
  46. userPasswordText.setPrefWidth(270);
  47. loginGrid.add(userPasswordText, 0, 5);
  48. //Login button
  49. Button btnLogin = new Button("Sign In");
  50. HBox hbBtnLogin = new HBox(270);
  51. hbBtnLogin.getChildren().add(btnLogin);
  52. btnLogin.setMaxHeight(24);
  53. btnLogin.setMaxWidth(270);
  54. btnLogin.setPrefSize(270, 24);
  55. loginGrid.add(hbBtnLogin, 0, 6);
  56. //Back Button
  57. Button btnBackLogin = new Button("Back");
  58. HBox hbBtnBackLogin = new HBox(270);
  59. hbBtnBackLogin.getChildren().add(btnBackLogin);
  60. btnBackLogin.setMaxHeight(24);
  61. btnBackLogin.setMaxWidth(270);
  62. btnBackLogin.setPrefSize(270, 24);
  63. loginGrid.add(hbBtnBackLogin, 0, 8);
  64. //Set Login Scene
  65. Scene loginScene = new Scene(loginGrid, 300, 275);
  66.  
  67. primaryStage.setScene(loginScene);
  68. primaryStage.show();
  69.  
  70. //Login button reads textfile to allow people to login
  71. btnLogin.setOnAction(e -> {
  72. try {
  73. // get the user name and password when user press on login button
  74. String userName = userNameText.getText();
  75. String password = userPasswordText.getText();
  76. Scanner read = null;
  77. int noOfLines = 0;
  78. try {
  79.  
  80. read = new Scanner(new BufferedReader(new FileReader("users.txt")));
  81. while (read.hasNext()) {
  82. //System.out.println(read.next());
  83. noOfLines++;
  84. for (int i = 0; i < noOfLines; i++) {
  85. if (read.nextLine().equals(userName)) { // if the same user name
  86.  
  87. if (read.hasNextLine() && read.nextLine().equals(password)) { // check password
  88. Alert loginSuccess = new Alert(Alert.AlertType.CONFIRMATION);
  89. loginSuccess.setTitle("Welcome");
  90. loginSuccess.setContentText("Welcome back!");
  91. loginSuccess.showAndWait();
  92. homepageConn.start(primaryStage);
  93. // if also same, change boolean to true
  94. break;// and break the for-loop
  95. }
  96. }
  97. }
  98. }
  99. Alert loginFailAlert = new Alert(Alert.AlertType.ERROR);
  100. loginFailAlert.setTitle("Incorrect Username/Password");
  101. loginFailAlert.setContentText("Incorrect Username/Password entered. Please try again!");
  102. loginFailAlert.showAndWait();
  103. userNameText.clear();
  104. userPasswordText.clear();
  105. } catch (FileNotFoundException ex) {
  106. Logger.getLogger(Homepage.class.getName()).log(Level.SEVERE, null, ex);
  107. } finally {
  108. if (read != null) {
  109. read.close();
  110. System.out.println(noOfLines);
  111. }
  112. }
  113. } catch (Exception ee) {
  114. ee.printStackTrace();
  115. }
  116. });
  117. //Back button to mainpage
  118. btnBackLogin.setOnAction(e -> {
  119. fanConn.start(primaryStage);
  120. });
  121.  
  122. }
  123.  
  124. //Getter and setter to get value for ThisUser in username textfield
  125. public void setName(String user) {
  126. ThisUser = user;
  127. }
  128.  
  129. public String getName() {
  130. return ThisUser;
  131. }
  132.  
  133. }
  134.  
  135. public class Homepage extends Fan2Fan {
  136.  
  137. public Homepage() {
  138. //Constructor
  139. }
  140.  
  141. @Override
  142. public void start(Stage primaryStage) {
  143. Fan2Fan fanConn = new Fan2Fan();
  144. Login loginConn = new Login();
  145. Signup signupConn = new Signup();
  146. Account accountConn = new Account();
  147. Homepage homepageConn = new Homepage();
  148. Matches matchesConn = new Matches();
  149. Rovers roversConn = new Rovers();
  150. Cork corkConn = new Cork();
  151. Dundalk dundalkConn = new Dundalk();
  152. Payment payConn = new Payment();
  153. Update updateConn = new Update();
  154.  
  155. //Declare Homepage grid
  156. GridPane homepageGrid = new GridPane();
  157. homepageGrid.setAlignment(Pos.CENTER);
  158. homepageGrid.setHgap(0);
  159. homepageGrid.setVgap(10);
  160. //Purchase tickets button
  161. Button btnPurchaseTickets = new Button("Purchase Tickets");
  162. HBox hbBtnPurchaseTickets = new HBox(270);
  163. hbBtnPurchaseTickets.getChildren().add(btnPurchaseTickets);
  164. btnPurchaseTickets.setMaxHeight(24);
  165. btnPurchaseTickets.setMaxWidth(270);
  166. btnPurchaseTickets.setPrefSize(270, 24);
  167. homepageGrid.add(hbBtnPurchaseTickets, 5, 0);
  168. //Account Info Button
  169. Button btnAccountInfo = new Button("Account Information");
  170. HBox hbBtnAccountInfo = new HBox(270);
  171. hbBtnAccountInfo.getChildren().add(btnAccountInfo);
  172. btnAccountInfo.setMaxHeight(24);
  173. btnAccountInfo.setMaxWidth(270);
  174. btnAccountInfo.setPrefSize(270, 24);
  175. homepageGrid.add(hbBtnAccountInfo, 5, 1);
  176. //Become Seller Button
  177. Button btnBecomeSeller = new Button("Become a Seller");
  178. HBox hbBtnBecomeSeller = new HBox(270);
  179. hbBtnBecomeSeller.getChildren().add(btnBecomeSeller);
  180. btnBecomeSeller.setMaxHeight(24);
  181. btnBecomeSeller.setMaxWidth(270);
  182. btnBecomeSeller.setPrefSize(270, 24);
  183. homepageGrid.add(hbBtnBecomeSeller, 5, 2);
  184. //Exit Button
  185. Button btnHomepageExit = new Button("Exit");
  186. HBox hbBtnHomepageExit = new HBox(270);
  187. hbBtnHomepageExit.getChildren().add(btnHomepageExit);
  188. btnHomepageExit.setMaxHeight(24);
  189. btnHomepageExit.setMaxWidth(270);
  190. btnHomepageExit.setPrefSize(270, 24);
  191. homepageGrid.add(hbBtnHomepageExit, 5, 3);
  192. //Declare Homepage scene
  193. Scene homepageScene = new Scene(homepageGrid, 300, 275);
  194.  
  195. primaryStage.setScene(homepageScene);
  196. primaryStage.show();
  197.  
  198. //Open account Information
  199. btnAccountInfo.setOnAction( e-> {
  200. accountConn.start(primaryStage);
  201. });
  202. //Open Match selection
  203. btnPurchaseTickets.setOnAction(e ->{
  204. matchesConn.start(primaryStage);
  205. });
  206. //Exit button button to homepage
  207. btnHomepageExit.setOnAction(e -> {
  208. primaryStage.close();
  209. });
  210.  
  211. }
  212. }
  213.  
  214. //AccountUserName Details
  215. Label accountUserLabel = new Label("User:");
  216. accountInfoGrid.add(accountUserLabel, 0, 2);
  217. Label loginUserLabel = new Label();
  218. loginUserLabel = loginConn.getName();
  219. accountInfoGrid.add(loginUserLabel, 1, 2);
Add Comment
Please, Sign In to add comment