diff --git a/src/wrestlingtournamentcli/Main.java b/src/wrestlingtournamentcli/Main.java index 53e5234..f4de309 100644 --- a/src/wrestlingtournamentcli/Main.java +++ b/src/wrestlingtournamentcli/Main.java @@ -10,6 +10,12 @@ import loggingFunctions.*; import javafx.scene.control.ListView; import java.io.File; + +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Scanner; + import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -448,9 +454,16 @@ public void start(Stage stage) throws Exception { Button save = new Button(); Button start = new Button(); + Button addNewTeams = new Button(); + + + + + Button wrestlerBack = new Button(); Button compareWrestlers = new Button(); TextField compareWrestlersTxt = new TextField(); + TextField saveTournament = new TextField(); TextField FirstName = new TextField(); TextField LastName = new TextField(); @@ -464,7 +477,7 @@ public void start(Stage stage) throws Exception { compareWrestlers.setText("Compare Wrestlers"); compareWrestlersTxt.setText("Name,Name"); ListView compareWrestlerView = new ListView(); - Button wrestlerBack = new Button(); + ListView startView = new ListView(); //button declarations i've added Button advance = new Button(); @@ -494,9 +507,10 @@ public void start(Stage stage) throws Exception { add.setText("Add Wrestler"); BorderPane introRoot= new BorderPane(); GridPane introLayout = new GridPane(); + introLayout.setAlignment(Pos.CENTER); Button wrestling = new Button(); Button soccer = new Button(); - Label introMenu = new Label("Please select the sport you would like to manage:"); + Label introMenu = new Label("Please select the sport you would like to manage:\t\t"); //UI elements for selection Screen BorderPane soccerRoot = new BorderPane(); Label soccerLabel = new Label("Soccer Menu"); @@ -538,10 +552,12 @@ public void start(Stage stage) throws Exception { wrestling.setPadding(new Insets(10,10,10,10)); soccer.setText("Soccer"); soccer.setPadding(new Insets(10,10,10,10)); - introLayout.setPadding(new Insets(300,100,100,100)); + + //introLayout.setPadding(new Insets(300,100,100,100)); introLayout.add(introMenu, 0, 0); - introLayout.add(wrestling, 2,3 ); - introLayout.add(soccer, 3, 3); + introLayout.add(wrestling, 1,0 ); + introLayout.add(new Label("\t"), 2, 0); + introLayout.add(soccer, 3, 0); introRoot.setCenter(introLayout); //Initializing introduction UI elements importTeams.setMinWidth(110); @@ -551,8 +567,13 @@ public void start(Stage stage) throws Exception { saveTournament.setMinWidth(110); save.setMinWidth(110); start.setMinWidth(110); - FirstName.setMinWidth(110); + + addNewTeams.setMinWidth(110); + addNewTeams.setText("Add your own Team"); + + FirstName.setMinWidth(110); LastName.setMinWidth(110); + update.setMinWidth(110); help.setMinWidth(110); advance.setMinWidth(110); @@ -585,9 +606,11 @@ public void start(Stage stage) throws Exception { layout.add(menu, 1, 0); layout.add(importWrestlers, 0, 1); layout.add(importTeams, 0, 3); + layout.add(addNewTeams, 1, 1); layout.add(viewTeams, 0, 4); layout.add(viewWrestlers, 0, 2); layout.add(save, 0, 5); + layout.add(saveTournament, 1, 5); layout.add(start, 0, 13); layout.add(add, 0, 6); @@ -598,6 +621,7 @@ public void start(Stage stage) throws Exception { layout.add(Weight, 1, 10); layout.add(TotalWins, 1,11); layout.add(TotalMatch, 1, 12); + layout.add(start, 0, 6); layout.add(compareWrestlers, 0, 7); @@ -605,10 +629,12 @@ public void start(Stage stage) throws Exception { layout.add(advance, 0, 9); layout.add(help, 0, 10); layout.add(update, 0, 11); - - Scene introScene = new Scene (introRoot, 700, 700); - Scene wrestlerScene = new Scene(root,700,700); - Scene soccerScene = new Scene(soccerRoot,700,700); + + layout.add(wrestlerBack, 0, 12); + + Scene introScene = new Scene (introRoot, 640, 480); + Scene wrestlerScene = new Scene(root,640,480); + Scene soccerScene = new Scene(soccerRoot,640,480); wrestling.setOnAction(e ->{ Model m = new Model("wrestling"); @@ -763,6 +789,131 @@ public void start(Stage stage) throws Exception { } }); + //Set the button on action, it will display labels and text field + // to allow theauser to input his/her own team information. + addNewTeams.setOnAction(e -> { + + + //Label and text field for the team name. + Label teamName = new Label("Team 1 Name:"); + TextField userOwnTeam1Name = new TextField(); + + //Label and textField for the team Initials + Label teamInitials = new Label("Team 1 Initials:"); + TextField userOwnTeamInitials = new TextField(); + + //Label and text field for team Mascot + Label teamMascot = new Label("Team 1 Mascot:"); + TextField userOwnTeamMascot = new TextField(); + + //Second Team Info: + + //Label and text field for the team name. + Label team2Name = new Label("Team 2 Name:"); + TextField userOwnTeam2Name = new TextField(); + + //Label and textField for the team Initials + Label team2Initials = new Label("Team 2 Initials:"); + TextField userOwnTeam2Initials = new TextField(); + + //Label and text field for team Mascot + Label team2Mascot = new Label("Team 2 Mascot:"); + TextField userOwnTeam2Mascot = new TextField(); + + Button addTeams = new Button("Add"); + + addTeams.setMinWidth(110); + + //Placing the labels and textField in the stage window for the first team. + layout.add(teamName, 1, 2); + layout.add(userOwnTeam1Name, 1, 3); + layout.add(teamInitials, 1, 4); + layout.add(userOwnTeamInitials, 1, 5); + layout.add(teamMascot, 1, 6); + layout.add(userOwnTeamMascot, 1, 7); + + //Placing the labels and textField in the stage window for the first team for Second Team + layout.add(team2Name, 2, 2); + layout.add(userOwnTeam2Name, 2, 3); + layout.add(team2Initials, 2, 4); + layout.add(userOwnTeam2Initials, 2, 5); + layout.add(team2Mascot, 2, 6); + layout.add(userOwnTeam2Mascot, 2, 7); + + layout.add(addTeams, 2, 8); + + + addTeams.setOnAction(e2 -> { + //Get user input and assign it to a String variable. + String teamNameText = userOwnTeam1Name.getText(); + String teamInitiText = userOwnTeamInitials.getText(); + String teamMascotText = userOwnTeamMascot.getText(); + + String teamNameText2 = userOwnTeam2Name.getText(); + String teamInitiText2 = userOwnTeam2Initials.getText(); + String teamMascotText2 = userOwnTeam2Mascot.getText(); + + //Check if any of the textFields is empty, if empty alert the user if not proceed to next code block + if (teamNameText.isEmpty() || teamInitiText.isEmpty() || teamMascotText.isEmpty() || + teamNameText2.isEmpty() || teamInitiText2.isEmpty() || teamMascotText2.isEmpty()){ + + Alert emptyTextField = new Alert(AlertType.ERROR); + emptyTextField.setTitle("ERROR"); + String errorMessage = "Please insert information in all text Fields"; + emptyTextField.setContentText(errorMessage); + emptyTextField.show(); + return; + + } + else { + + try { + //Create a file that will store the user input. + File newFile = new File("myTeams.txt"); + + FileWriter writeTo = new FileWriter("myTeams.txt"); + PrintWriter printToFile = new PrintWriter(writeTo); + + printToFile.print(teamNameText + ", "); + printToFile.print(teamInitiText + ", "); + printToFile.print(teamMascotText + ", "); + printToFile.print("\n"); + + printToFile.print(teamNameText2 + ", "); + printToFile.print(teamInitiText2 + ", "); + printToFile.print(teamMascotText2 + ", "); + printToFile.close(); + + + Alert addAlert = new Alert(AlertType.CONFIRMATION); + addAlert.setTitle("Alert"); + String addMsg = "Your teams added successfully, please Import the file 'myTeams.txt' by using 'Import Teams' Button "; + addAlert.setContentText(addMsg); + addAlert.show(); + + + } + + catch (Exception ex) { + + Alert createFileError = new Alert(AlertType.ERROR); + createFileError.setTitle("DONE!"); + String errorMessage = "The file is not exists"; + createFileError.setContentText(errorMessage); + createFileError.show(); + return; + } + + } + + }); + + }); + + + + + importWrestlers.setOnAction(e -> { FileChooser fc = new FileChooser(); File seletedFile = fc.showOpenDialog(null);