Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Login extends Fan2Fan {
- public Login() {
- //Constructor
- }
- String ThisUser;
- @Override
- public void start(Stage primaryStage) {
- Fan2Fan fanConn = new Fan2Fan();
- Login loginConn = new Login();
- Signup signupConn = new Signup();
- Account accountConn = new Account();
- Homepage homepageConn = new Homepage();
- Matches matchesConn = new Matches();
- Rovers roversConn = new Rovers();
- Cork corkConn = new Cork();
- Dundalk dundalkConn = new Dundalk();
- Payment payConn = new Payment();
- Update updateConn = new Update();
- //Declare Login Page
- GridPane loginGrid = new GridPane();
- loginGrid.setAlignment(Pos.CENTER);
- loginGrid.setHgap(0);
- loginGrid.setVgap(10);
- //Login page title
- Text loginTitle = new Text("Please Login");
- loginTitle.setFont(Font.font("Tahoma", FontWeight.BOLD, 20));
- loginGrid.add(loginTitle, 0, 0, 5, 1);
- //Login UserName Details
- Label userNameLabel = new Label("User Name: ");
- loginGrid.add(userNameLabel, 0, 1);
- TextField userNameText = new TextField();
- userNameText.setPrefWidth(270);
- loginGrid.add(userNameText, 0, 2);
- ThisUser = userNameText.getText();
- //Login Password Details
- Label userPasswordLabel = new Label("Password: ");
- loginGrid.add(userPasswordLabel, 0, 4);
- PasswordField userPasswordText = new PasswordField();
- Label accountUserPassLabel = new Label();
- Tooltip tipPassword = new Tooltip();
- tipPassword.setText("Password is case sensitive");
- userPasswordText.setTooltip(tipPassword);
- userPasswordText.setPrefWidth(270);
- loginGrid.add(userPasswordText, 0, 5);
- //Login button
- Button btnLogin = new Button("Sign In");
- HBox hbBtnLogin = new HBox(270);
- hbBtnLogin.getChildren().add(btnLogin);
- btnLogin.setMaxHeight(24);
- btnLogin.setMaxWidth(270);
- btnLogin.setPrefSize(270, 24);
- loginGrid.add(hbBtnLogin, 0, 6);
- //Back Button
- Button btnBackLogin = new Button("Back");
- HBox hbBtnBackLogin = new HBox(270);
- hbBtnBackLogin.getChildren().add(btnBackLogin);
- btnBackLogin.setMaxHeight(24);
- btnBackLogin.setMaxWidth(270);
- btnBackLogin.setPrefSize(270, 24);
- loginGrid.add(hbBtnBackLogin, 0, 8);
- //Set Login Scene
- Scene loginScene = new Scene(loginGrid, 300, 275);
- primaryStage.setScene(loginScene);
- primaryStage.show();
- //Login button reads textfile to allow people to login
- btnLogin.setOnAction(e -> {
- try {
- // get the user name and password when user press on login button
- String userName = userNameText.getText();
- String password = userPasswordText.getText();
- Scanner read = null;
- int noOfLines = 0;
- try {
- read = new Scanner(new BufferedReader(new FileReader("users.txt")));
- while (read.hasNext()) {
- //System.out.println(read.next());
- noOfLines++;
- for (int i = 0; i < noOfLines; i++) {
- if (read.nextLine().equals(userName)) { // if the same user name
- if (read.hasNextLine() && read.nextLine().equals(password)) { // check password
- Alert loginSuccess = new Alert(Alert.AlertType.CONFIRMATION);
- loginSuccess.setTitle("Welcome");
- loginSuccess.setContentText("Welcome back!");
- loginSuccess.showAndWait();
- homepageConn.start(primaryStage);
- // if also same, change boolean to true
- break;// and break the for-loop
- }
- }
- }
- }
- Alert loginFailAlert = new Alert(Alert.AlertType.ERROR);
- loginFailAlert.setTitle("Incorrect Username/Password");
- loginFailAlert.setContentText("Incorrect Username/Password entered. Please try again!");
- loginFailAlert.showAndWait();
- userNameText.clear();
- userPasswordText.clear();
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Homepage.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- if (read != null) {
- read.close();
- System.out.println(noOfLines);
- }
- }
- } catch (Exception ee) {
- ee.printStackTrace();
- }
- });
- //Back button to mainpage
- btnBackLogin.setOnAction(e -> {
- fanConn.start(primaryStage);
- });
- }
- //Getter and setter to get value for ThisUser in username textfield
- public void setName(String user) {
- ThisUser = user;
- }
- public String getName() {
- return ThisUser;
- }
- }
- public class Homepage extends Fan2Fan {
- public Homepage() {
- //Constructor
- }
- @Override
- public void start(Stage primaryStage) {
- Fan2Fan fanConn = new Fan2Fan();
- Login loginConn = new Login();
- Signup signupConn = new Signup();
- Account accountConn = new Account();
- Homepage homepageConn = new Homepage();
- Matches matchesConn = new Matches();
- Rovers roversConn = new Rovers();
- Cork corkConn = new Cork();
- Dundalk dundalkConn = new Dundalk();
- Payment payConn = new Payment();
- Update updateConn = new Update();
- //Declare Homepage grid
- GridPane homepageGrid = new GridPane();
- homepageGrid.setAlignment(Pos.CENTER);
- homepageGrid.setHgap(0);
- homepageGrid.setVgap(10);
- //Purchase tickets button
- Button btnPurchaseTickets = new Button("Purchase Tickets");
- HBox hbBtnPurchaseTickets = new HBox(270);
- hbBtnPurchaseTickets.getChildren().add(btnPurchaseTickets);
- btnPurchaseTickets.setMaxHeight(24);
- btnPurchaseTickets.setMaxWidth(270);
- btnPurchaseTickets.setPrefSize(270, 24);
- homepageGrid.add(hbBtnPurchaseTickets, 5, 0);
- //Account Info Button
- Button btnAccountInfo = new Button("Account Information");
- HBox hbBtnAccountInfo = new HBox(270);
- hbBtnAccountInfo.getChildren().add(btnAccountInfo);
- btnAccountInfo.setMaxHeight(24);
- btnAccountInfo.setMaxWidth(270);
- btnAccountInfo.setPrefSize(270, 24);
- homepageGrid.add(hbBtnAccountInfo, 5, 1);
- //Become Seller Button
- Button btnBecomeSeller = new Button("Become a Seller");
- HBox hbBtnBecomeSeller = new HBox(270);
- hbBtnBecomeSeller.getChildren().add(btnBecomeSeller);
- btnBecomeSeller.setMaxHeight(24);
- btnBecomeSeller.setMaxWidth(270);
- btnBecomeSeller.setPrefSize(270, 24);
- homepageGrid.add(hbBtnBecomeSeller, 5, 2);
- //Exit Button
- Button btnHomepageExit = new Button("Exit");
- HBox hbBtnHomepageExit = new HBox(270);
- hbBtnHomepageExit.getChildren().add(btnHomepageExit);
- btnHomepageExit.setMaxHeight(24);
- btnHomepageExit.setMaxWidth(270);
- btnHomepageExit.setPrefSize(270, 24);
- homepageGrid.add(hbBtnHomepageExit, 5, 3);
- //Declare Homepage scene
- Scene homepageScene = new Scene(homepageGrid, 300, 275);
- primaryStage.setScene(homepageScene);
- primaryStage.show();
- //Open account Information
- btnAccountInfo.setOnAction( e-> {
- accountConn.start(primaryStage);
- });
- //Open Match selection
- btnPurchaseTickets.setOnAction(e ->{
- matchesConn.start(primaryStage);
- });
- //Exit button button to homepage
- btnHomepageExit.setOnAction(e -> {
- primaryStage.close();
- });
- }
- }
- //AccountUserName Details
- Label accountUserLabel = new Label("User:");
- accountInfoGrid.add(accountUserLabel, 0, 2);
- Label loginUserLabel = new Label();
- loginUserLabel = loginConn.getName();
- accountInfoGrid.add(loginUserLabel, 1, 2);
Add Comment
Please, Sign In to add comment