From a3340f193bab9039ee29b9a014467092591f8756 Mon Sep 17 00:00:00 2001 From: nhasan8 <43551577+nhasan8@users.noreply.github.com> Date: Fri, 27 Mar 2020 16:25:51 -0400 Subject: [PATCH 1/4] Add your own team button User is able to add their own team and import the new team --- src/wrestlingtournamentcli/Main.java | 133 ++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/src/wrestlingtournamentcli/Main.java b/src/wrestlingtournamentcli/Main.java index fdb1994..598d4e9 100644 --- a/src/wrestlingtournamentcli/Main.java +++ b/src/wrestlingtournamentcli/Main.java @@ -7,6 +7,8 @@ import DataClasses.*; 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; @@ -312,6 +314,8 @@ public void start(Stage stage) throws Exception { Button importWrestlers = new Button(); Button save = new Button(); Button start = new Button(); + Button addNewTeams = new Button(); + TextField saveTournament = new TextField(); ListView listView = new ListView(); @@ -329,6 +333,8 @@ public void start(Stage stage) throws Exception { saveTournament.setMinWidth(110); save.setMinWidth(110); start.setMinWidth(110); + addNewTeams.setMinWidth(110); + addNewTeams.setText("Add your own Team"); save.setText("Save"); start.setText("Start"); @@ -347,10 +353,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(saveTournament, 1, 8); layout.add(start, 0, 6); viewTeams.setOnAction(e -> { @@ -406,6 +413,130 @@ public void start(Stage stage) throws Exception { } }); + //Set the button on action, it will display labels and text field + // to allow the user 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(); From 55ffcaab8046172824ff636252ab57c2c29142ff Mon Sep 17 00:00:00 2001 From: nhasan8 <43551577+nhasan8@users.noreply.github.com> Date: Fri, 17 Apr 2020 13:53:39 -0400 Subject: [PATCH 2/4] Compilation error fix --- src/wrestlingtournamentcli/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrestlingtournamentcli/Main.java b/src/wrestlingtournamentcli/Main.java index 9d48972..64b3308 100644 --- a/src/wrestlingtournamentcli/Main.java +++ b/src/wrestlingtournamentcli/Main.java @@ -465,7 +465,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(); From ae3c1aa9dcfd30bb5c5485675cf690f94d4929a3 Mon Sep 17 00:00:00 2001 From: nhasan8 <43551577+nhasan8@users.noreply.github.com> Date: Mon, 20 Apr 2020 14:25:37 -0400 Subject: [PATCH 3/4] Fix for #58. Application window - oversized on start and intial screen is not formatted well. Application window is smaller and initial scene is centered and well formatted. --- src/wrestlingtournamentcli/Main.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/wrestlingtournamentcli/Main.java b/src/wrestlingtournamentcli/Main.java index eadada2..ee6d420 100644 --- a/src/wrestlingtournamentcli/Main.java +++ b/src/wrestlingtournamentcli/Main.java @@ -506,9 +506,10 @@ public void start(Stage stage) throws Exception { 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(); @@ -551,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 @@ -613,13 +616,13 @@ public void start(Stage stage) throws Exception { layout.add(advance, 0, 9); layout.add(help, 0, 10); layout.add(update, 0, 11); - + layout.add(wrestlerBack, 0, 12); - Scene introScene = new Scene (introRoot, 700, 700); - Scene wrestlerScene = new Scene(root,700,700); - Scene soccerScene = new Scene(soccerRoot,700,700); + Scene introScene = new Scene (introRoot, 640, 480); + Scene wrestlerScene = new Scene(root,640,480); + Scene soccerScene = new Scene(soccerRoot,640,480); wrestling.setOnAction(e ->{ From 75b75c5330bc466a11e8c1368f2836533e122019 Mon Sep 17 00:00:00 2001 From: nhasan8 <43551577+nhasan8@users.noreply.github.com> Date: Wed, 22 Apr 2020 13:37:56 -0400 Subject: [PATCH 4/4] Build error issue --- src/wrestlingtournamentcli/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrestlingtournamentcli/Main.java b/src/wrestlingtournamentcli/Main.java index 6f2ff2f..dec73fc 100644 --- a/src/wrestlingtournamentcli/Main.java +++ b/src/wrestlingtournamentcli/Main.java @@ -457,7 +457,7 @@ public void start(Stage stage) throws Exception { - Button addNewTeams = new Button(); + Button wrestlerBack = new Button(); Button compareWrestlers = new Button();