Guest User

Untitled

a guest
Jan 1st, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 70.72 KB | None | 0 0
  1. package proj5;
  2.  
  3. //Made my Dominick Gurnari for CS0401 Mohinder Dick Project 5 SassySoccerAppV4 Sorry its a lot of code but the functionality is there
  4.  
  5. import java.awt.MenuItem;
  6. import java.awt.TextArea;
  7. import java.io.File;
  8. import java.io.FileNotFoundException;
  9. import java.io.FileWriter;
  10. import java.io.IOException;
  11. import java.io.PrintWriter;
  12. import java.util.ArrayList;
  13. import java.util.Arrays;
  14. import java.util.Collection;
  15. import java.util.Collections;
  16. import java.util.Comparator;
  17. import java.util.HashSet;
  18. import java.util.Optional;
  19. import java.util.Scanner;
  20. import java.util.Set;
  21.  
  22. import javafx.application.Application;
  23. import javafx.event.ActionEvent;
  24. import javafx.event.EventHandler;
  25. import javafx.geometry.Insets;
  26. import javafx.geometry.Pos;
  27. import javafx.scene.layout.BorderPane;
  28. import javafx.scene.layout.HBox;
  29. import javafx.scene.layout.VBox;
  30. import javafx.scene.text.Text;
  31. import javafx.scene.Node;
  32. import javafx.scene.Scene;
  33. import javafx.scene.control.Alert;
  34. import javafx.scene.control.Alert.AlertType;
  35. import javafx.scene.control.Button;
  36. import javafx.scene.control.ButtonType;
  37. import javafx.scene.control.Label;
  38. import javafx.scene.control.ListView;
  39. import javafx.scene.control.Menu; //Imports most controls like Button and MenuBar
  40. import javafx.scene.control.MenuBar;
  41. import javafx.scene.control.TextField;
  42. import javafx.stage.Modality;
  43. import javafx.stage.Stage;
  44.  
  45. import cs401.sassy.tracker.data.*;
  46.  
  47. /*
  48. A simple JavaFX application
  49. */
  50. public class Proj4Test extends Application {
  51.  
  52. public static Scanner scan = new Scanner(System.in);
  53.  
  54. //all boolean values
  55. public static boolean VIPstatus = false;
  56. public static boolean running = true;
  57. public static boolean listCreated = false;
  58. public static boolean goalsSortDescending = true;
  59. public static boolean namesOrderAscending = true;
  60. public static boolean showSummary = true;
  61. public static boolean fileExists = false;
  62. public static boolean firstTime = true;
  63. public static boolean connect = true;
  64.  
  65. public static String goalsSortStatus = "Descending";
  66. public static String namesSortStatus = "Ascending";
  67. public static String passwordEntry;
  68. public static String password = "#ChelseaIsTheBest";
  69.  
  70. public static int goalstotal = 0;
  71. public static int goalstotalExternal = 0;
  72. public static int amountOfPlayers = 0;
  73. public static int amountOfPlayersRegular = 0;
  74.  
  75. VBox sceneBoxUpdate;
  76. HBox topBoxUpdate;
  77. HBox topBoxConnect;
  78. Label UpdateLabel;
  79. Label ConnectLabel;
  80. Label DisconnectLabel;
  81. static ListView<String> UpdateListView;
  82. static ListView<String> ConnectListView;
  83. Button submitButtonUpdate;
  84.  
  85. static Text textArea;
  86.  
  87. static Stage updateStage = new Stage();
  88.  
  89. //created Arraylist for easy sort and access
  90. public static ArrayList<SoccerPlayer> playerList = new ArrayList<SoccerPlayer>();
  91. public static ArrayList<User> playerListVIP = new ArrayList<User>();
  92. public static ArrayList<User> connectedVIPS = new ArrayList<User>();
  93. public static Scanner in = new Scanner(System.in);
  94.  
  95. public void start(Stage primaryStage) {
  96.  
  97. //Set the title of the scene (i.e. Window title)
  98. primaryStage.setTitle("Sassy Soocer App Version 4.0");
  99.  
  100. Label passwordLabel = new Label("Please enter a password to continue as Vip, or "
  101. + "\npress enter to continue as a regular user");
  102. passwordLabel.setMinWidth(100);
  103. TextField passwordTextField = new TextField();
  104. passwordTextField.setMinWidth(100);
  105.  
  106. // Create a button UI element
  107. Button btn = new Button();
  108.  
  109. // Set the text, X & Y coordinates
  110. btn.setLayoutX(100);
  111. btn.setLayoutY(80);
  112. btn.setText("Enter");
  113.  
  114. //SET UP STAGE AND SCENE AND PANE
  115.  
  116. VBox passwordPane = new VBox(10, passwordLabel, passwordTextField);
  117. passwordPane.setAlignment(Pos.CENTER);
  118. passwordPane.getChildren().add(btn);
  119.  
  120. Scene scene = new Scene(passwordPane, 300, 250);
  121. primaryStage.setScene(scene);
  122. primaryStage.show();
  123.  
  124. //PASSWORD BUTTON ACTION
  125.  
  126. btn.setOnAction(e -> {
  127.  
  128. passwordEntry = passwordTextField.getText();
  129.  
  130. if(passwordEntry.equals(password)) {
  131.  
  132. textArea = new Text("");
  133.  
  134. // Create Pane to host UI elements
  135. VBox pane = new VBox();
  136.  
  137. // Create menu bar to host menu items
  138. MenuBar mainMenu = new MenuBar();
  139.  
  140. // Create new menus to the bar
  141. Menu fileTab = new Menu("File");
  142.  
  143. javafx.scene.control.MenuItem importPlayerListTab = new javafx.scene.control.MenuItem("Import Player List");
  144. javafx.scene.control.MenuItem importPrefencesTab = new javafx.scene.control.MenuItem("Import Preferences");
  145. javafx.scene.control.MenuItem savetab = new javafx.scene.control.MenuItem("Save All");
  146. javafx.scene.control.MenuItem exitMenuTab = new javafx.scene.control.MenuItem("Exit");
  147.  
  148. Menu playerListTab = new Menu("Players");
  149.  
  150. javafx.scene.control.MenuItem createNewListTab = new javafx.scene.control.MenuItem("Create New List");
  151. javafx.scene.control.MenuItem viewPlayerListTab = new javafx.scene.control.MenuItem("View");
  152. javafx.scene.control.MenuItem updatePlayerListTab = new javafx.scene.control.MenuItem("Update Players");
  153. javafx.scene.control.MenuItem removePlayersTab = new javafx.scene.control.MenuItem("Remove Players");
  154.  
  155. Menu goalListTab = new Menu("Goal List");
  156.  
  157. javafx.scene.control.MenuItem viewGoalsTab = new javafx.scene.control.MenuItem("View");
  158. javafx.scene.control.MenuItem addGoalsTab = new javafx.scene.control.MenuItem("Add Goals");
  159.  
  160. Menu preferencesTab = new Menu("Prefences");
  161.  
  162. javafx.scene.control.MenuItem viewPreferencesTab = new javafx.scene.control.MenuItem("View");
  163. javafx.scene.control.MenuItem updatePasswordTab = new javafx.scene.control.MenuItem("Update Password");
  164. javafx.scene.control.MenuItem connectToVIPTab = new javafx.scene.control.MenuItem("Connect to Others");
  165. javafx.scene.control.MenuItem disconnectVIPTab = new javafx.scene.control.MenuItem("Disconnect from Others");
  166. javafx.scene.control.MenuItem changeGoalSortTab = new javafx.scene.control.MenuItem("Change Goal Sort");
  167. javafx.scene.control.MenuItem changeNameSortTab = new javafx.scene.control.MenuItem("Change Name Sort");
  168. javafx.scene.control.MenuItem changeSummaryTab = new javafx.scene.control.MenuItem("Change Summary Display");
  169. javafx.scene.control.MenuItem saveVIPConnectionList = new javafx.scene.control.MenuItem("Save VIP Connections");
  170.  
  171.  
  172. Menu connectionsTab = new Menu("Connections");
  173.  
  174. javafx.scene.control.MenuItem connectionsShowTab = new javafx.scene.control.MenuItem("Active Connections");
  175.  
  176. //NEW SCENE
  177.  
  178. Scene sceneMain = new Scene(pane, 500, 650);
  179. primaryStage.setScene(sceneMain);
  180. primaryStage.show();
  181.  
  182. Stage dialogStage = new Stage();
  183. dialogStage.initModality(Modality.WINDOW_MODAL);
  184.  
  185. VBox vbox = new VBox(new Text("Sent to the VIP Menu"));
  186. vbox.setAlignment(Pos.CENTER);
  187. vbox.setPadding(new Insets(15));
  188.  
  189. //SENT TO VIP MENU
  190.  
  191. dialogStage.setScene(new Scene(vbox));
  192. dialogStage.show();
  193.  
  194. //ACTION COMMANDS FOR EACH TAB
  195.  
  196. createNewListTab.setOnAction(r -> {
  197. if(listCreated == false) {
  198. //SET AMOUNT OF PLAYERS
  199. Label playerAmountLabel = new Label("Please enter the number of players that would like to track 8 max");
  200. playerAmountLabel.setMinWidth(100);
  201. TextField playerAmountTextField = new TextField();
  202. playerAmountTextField.setMinWidth(100);
  203. //
  204. Button btnCreateList = new Button();
  205. //
  206. // Set the text, X & Y coordinates
  207. btnCreateList.setLayoutX(100);
  208. btnCreateList.setLayoutY(80);
  209. btnCreateList.setText("Enter");
  210. //
  211. VBox createPane = new VBox(10, playerAmountLabel, playerAmountTextField);
  212. createPane.setAlignment(Pos.CENTER);
  213. createPane.getChildren().add(btnCreateList);
  214.  
  215. Stage stag2 = new Stage();
  216.  
  217. Scene sceneCreatePlayerAmount = new Scene(createPane, 300, 250);
  218. stag2.setScene(sceneCreatePlayerAmount);
  219. stag2.show();
  220.  
  221. btnCreateList.setOnAction(a -> {
  222.  
  223. amountOfPlayers = Integer.parseInt(playerAmountTextField.getText());
  224. System.out.println(amountOfPlayers);
  225. stag2.close();
  226.  
  227. //CREATES EMPTY FILE TO BEGIN STORING DATA IF FILE DOES NOT EXIST
  228. try {
  229. createEmptyFile();
  230. } catch (FileNotFoundException e1) {
  231. // TODO Auto-generated catch block
  232. e1.printStackTrace();
  233. }
  234.  
  235. if (amountOfPlayers <=8 && amountOfPlayers >0) {
  236.  
  237. //WARNING
  238. System.out.println("**** CAUTION ****\nCreating Players with duplicate names will\ncause your list to be deleted.\n");
  239. Stage dialogStageWarning = new Stage();
  240. //dialogStageWarning.initModality(Modality.WINDOW_MODAL);
  241.  
  242. VBox vboxWarning = new VBox(new Text("**** CAUTION ****\nCreating Players with duplicate names will\ncause your list to be deleted.\n"));
  243. vboxWarning.setAlignment(Pos.CENTER);
  244. vboxWarning.setPadding(new Insets(15));
  245.  
  246. dialogStageWarning.setScene(new Scene(vboxWarning));
  247. dialogStageWarning.show();
  248.  
  249. //CREATES PLAYER OBJECTS
  250. for (int i =0; i < amountOfPlayers; i++) {
  251. Label playerNameLabel = new Label("Please enter the name of player ");
  252. playerNameLabel.setMinWidth(100);
  253. TextField playerNameTextField = new TextField();
  254. playerNameTextField.setMinWidth(100);
  255. //
  256. Button btnPlayerName = new Button();
  257. //
  258. // Set the text, X & Y coordinates
  259. btnPlayerName.setLayoutX(100);
  260. btnPlayerName.setLayoutY(80);
  261. btnPlayerName.setText("Enter");
  262. //
  263. VBox createPlayerNamePane = new VBox(10, playerNameLabel, playerNameTextField);
  264. createPlayerNamePane.getChildren().add(btnPlayerName);
  265.  
  266. Scene sceneCreatePlayerName = new Scene(createPlayerNamePane, 300, 250);
  267. Stage playerNameSet = new Stage();
  268. playerNameSet.setScene(sceneCreatePlayerName);
  269. playerNameSet.show();
  270.  
  271. btnPlayerName.setOnAction(v -> {
  272.  
  273. playerNameSet.close();
  274. String playerName = playerNameTextField.getText();
  275. System.out.println(playerName);
  276. SoccerPlayer player = new SoccerPlayer(playerName);
  277. playerList.add(player);
  278.  
  279. });
  280.  
  281. }
  282.  
  283. //LIST CREATED
  284. listCreated = true;
  285. //CHECK DUPLICATE VALUES
  286. checkDuplicate();
  287.  
  288. } else {
  289. //CATCH
  290. textArea.setText("You must enter a number between 0 and 8");
  291. }
  292. });
  293. } else {
  294. textArea.setText("You must delete a list first");
  295. }
  296. });
  297.  
  298. //DISPLAYS PLAYERS
  299. viewPlayerListTab.setOnAction(r -> {
  300.  
  301. if(listCreated == true) {
  302. textArea.setText("");
  303. String a = "";
  304. SoccerPlayer empty = new SoccerPlayer("");
  305. playerList.add(empty);
  306. for(int u =0; u < amountOfPlayers; u++) {
  307. a = a + playerList.get(u).getName() + "\n";
  308. //textArea.setText("\n " + playerList.get(u).getName());
  309. //pane.getChildren().add(new Text(playerList.get(u).getName()));
  310. }
  311. textArea.setText(a);
  312. playerList.remove(empty);
  313. } else {
  314. textArea.setText("You must create a list first");
  315.  
  316. }
  317. });
  318.  
  319. //UPDATES PLAYERS WITH LISTVIEW
  320.  
  321. updatePlayerListTab.setOnAction(x -> {
  322.  
  323. //LISTVIEW
  324.  
  325. if(listCreated == true) {
  326. UpdateLabel = new Label("Choose a Player:");
  327. UpdateListView = new ListView<String>();
  328. for(int p = 0; p < amountOfPlayers; p++) {
  329. SoccerPlayer empty = new SoccerPlayer("");
  330. playerList.add(empty);
  331. UpdateListView.getItems().addAll(playerList.get(p).getName());
  332. playerList.remove(empty);
  333. }
  334.  
  335. topBoxUpdate = new HBox(60, UpdateLabel, UpdateListView);
  336. topBoxUpdate.setPadding(new Insets(10, 20, 10, 20));
  337. topBoxUpdate.setAlignment(Pos.CENTER);
  338.  
  339. submitButtonUpdate = new Button("SELECT");
  340. submitButtonUpdate.setOnAction(z -> updatePlayer());
  341.  
  342. sceneBoxUpdate = new VBox(topBoxUpdate, submitButtonUpdate);
  343. sceneBoxUpdate.setAlignment(Pos.CENTER);
  344.  
  345. Scene sceneUpdate = new Scene(sceneBoxUpdate, 500, 400);
  346. updateStage.setScene(sceneUpdate);
  347. updateStage.show();
  348. } else {
  349. textArea.setText("You must create a list first");
  350. }
  351. });
  352.  
  353. //LISTVIEW TO REMOVE PLAYERS ALSO
  354.  
  355. removePlayersTab.setOnAction(y -> {
  356. if(listCreated == true) {
  357. UpdateLabel = new Label("Choose a Player:");
  358. UpdateListView = new ListView<String>();
  359. for(int p = 0; p < amountOfPlayers; p++) {
  360. UpdateListView.getItems().addAll(playerList.get(p).getName());
  361. }
  362.  
  363. UpdateListView.getItems().addAll("Clear all");
  364.  
  365. topBoxUpdate = new HBox(60, UpdateLabel, UpdateListView);
  366. topBoxUpdate.setPadding(new Insets(10, 20, 10, 20));
  367. topBoxUpdate.setAlignment(Pos.CENTER);
  368.  
  369. submitButtonUpdate = new Button("SELECT");
  370. submitButtonUpdate.setOnAction(z -> removePlayer());
  371.  
  372. sceneBoxUpdate = new VBox(topBoxUpdate, submitButtonUpdate);
  373. sceneBoxUpdate.setAlignment(Pos.CENTER);
  374.  
  375. Scene sceneUpdate = new Scene(sceneBoxUpdate, 500, 400);
  376. updateStage.setScene(sceneUpdate);
  377. updateStage.show();
  378. } else {
  379. textArea.setText("You must create a list first");
  380. }
  381. });
  382.  
  383. //VIEWS GOALS AND SUMMARY ETC
  384.  
  385. viewGoalsTab.setOnAction(b -> {
  386. if(listCreated == true) {
  387. if(namesOrderAscending) {
  388. sortNames();
  389. } else {
  390. sortNamesDescending();
  391. }
  392.  
  393. if(goalsSortDescending) {
  394. sortGoals();
  395. } else {
  396. sortGoalsAscending();
  397. }
  398.  
  399. //TEXT AREA TEXT SET TO PREVENT MULTIPLE TEXT DISPLAY AT ONCE
  400. textArea.setText("");
  401. String a = "";
  402. String c ="";
  403. SoccerPlayer empty = new SoccerPlayer("");
  404. playerList.add(empty);
  405. for(int u =0; u < amountOfPlayers; u++) {
  406. a = a + playerList.get(u).getName() + " " + playerList.get(u).getgoals() + "\n";
  407. //textArea.setText("\n " + playerList.get(u).getName());
  408. //pane.getChildren().add(new Text(playerList.get(u).getName()));
  409. }
  410.  
  411. a = "Your list:\n" + a + "\n";
  412.  
  413. if(showSummary) {
  414. a = a + showPlayerSummary() + "\n";
  415. } else {
  416. //nothing shown
  417. }
  418.  
  419.  
  420. for(User u:connectedVIPS)
  421. {
  422. a += "\n" + ("User " + u.getName() + " with ID " + u.getUserID() + " players:\n\n");
  423.  
  424. if(namesOrderAscending) {
  425. sortNamesExternal(u.getUserID());
  426. } else {
  427. sortNamesDescendingExternal(u.getUserID());
  428. }
  429.  
  430. if(goalsSortDescending) {
  431. sortGoalsExternal(u.getUserID());
  432. } else {
  433. sortGoalsAscendingExternal(u.getUserID());
  434. }
  435.  
  436. for(Sasser i:u.getSassers())
  437. {
  438. a += (i.getName() + " " + i.getGoals() + "\n");
  439. }
  440.  
  441.  
  442. if(showSummary) {
  443. a += "\n" + showPlayerSummaryExternal(u.getUserID());
  444. }
  445. goalstotalExternal = 0;
  446.  
  447. }
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454. textArea.setText(a);
  455. playerList.remove(empty);
  456. goalstotal = 0;
  457.  
  458. } else {
  459. //CATCH
  460. textArea.setText("you must make a list first");
  461.  
  462. }
  463. });
  464.  
  465. //ADDS GOALS WITH LISTVIEW
  466. addGoalsTab.setOnAction(x -> {
  467. if(listCreated == true) {
  468. UpdateLabel = new Label("Choose a Player:");
  469. UpdateListView = new ListView<String>();
  470. for(int p = 0; p < amountOfPlayers; p++) {
  471. SoccerPlayer empty = new SoccerPlayer("");
  472. playerList.add(empty);
  473. UpdateListView.getItems().addAll(playerList.get(p).getName());
  474. playerList.remove(empty);
  475. }
  476.  
  477. topBoxUpdate = new HBox(60, UpdateLabel, UpdateListView);
  478. topBoxUpdate.setPadding(new Insets(10, 20, 10, 20));
  479. topBoxUpdate.setAlignment(Pos.CENTER);
  480.  
  481. submitButtonUpdate = new Button("SELECT");
  482. submitButtonUpdate.setOnAction(z -> updatePlayerGoals());
  483.  
  484. sceneBoxUpdate = new VBox(topBoxUpdate, submitButtonUpdate);
  485. sceneBoxUpdate.setAlignment(Pos.CENTER);
  486.  
  487. Scene sceneUpdate = new Scene(sceneBoxUpdate, 500, 400);
  488. updateStage.setScene(sceneUpdate);
  489. updateStage.show();
  490. } else {
  491. pane.getChildren().add(new Text("You must make a list first"));
  492. }
  493. });
  494.  
  495. //DISPLAYS PREFERENCES
  496. viewPreferencesTab.setOnAction(d -> {
  497.  
  498. textArea.setText("");
  499. String a = "1. Goals sort order " + "[" + goalsSortStatus + "]"
  500. + "\n2. Names sort order " + "[" + namesSortStatus + "]" +
  501. "\n3. Show goal summary " + "[" + showSummary + "]"
  502. + "\n4. Return to main menu\n";
  503.  
  504. textArea.setText(a);
  505. });
  506.  
  507. //CHANGE PREFERENCES
  508. changeGoalSortTab.setOnAction(w -> {
  509. //ALERTS ARE A GOOD WAY TO CONFIRM
  510. Alert confirm =
  511. new Alert(AlertType.CONFIRMATION,
  512. "Are you sure you do that?!!!");
  513.  
  514. Optional<ButtonType> response = confirm.showAndWait();
  515.  
  516. if(response.isPresent() && response.get() == ButtonType.CANCEL) {
  517. System.out.println("You cancelled.");
  518.  
  519. } else {
  520.  
  521. if(goalsSortDescending) {
  522.  
  523. goalsSortDescending = false;
  524. goalsSortStatus = "Ascending";
  525. textArea.setText("Goals sort order set to " + goalsSortStatus);
  526.  
  527. } else {
  528.  
  529. goalsSortDescending = true;
  530. goalsSortStatus = "Descending";
  531. textArea.setText("Goals sort order set to " + goalsSortStatus);
  532. }
  533. }
  534. });
  535.  
  536. changeNameSortTab.setOnAction(c -> {
  537.  
  538. Alert confirm =
  539. new Alert(AlertType.CONFIRMATION,
  540. "Are you sure you do that?!!!");
  541.  
  542. Optional<ButtonType> response = confirm.showAndWait();
  543.  
  544. if(response.isPresent() && response.get() == ButtonType.CANCEL) {
  545. System.out.println("You cancelled.");
  546.  
  547. } else {
  548.  
  549. if(namesOrderAscending) {
  550.  
  551. namesOrderAscending = false;
  552. namesSortStatus = "Descending";
  553. textArea.setText("Name sort order set to " + namesSortStatus);
  554. } else {
  555.  
  556. namesOrderAscending = true;
  557. namesSortStatus = "Ascending";
  558. textArea.setText("Name sort order set to " + namesSortStatus);
  559. }
  560. }
  561. });
  562.  
  563. changeSummaryTab.setOnAction(q -> {
  564.  
  565. Alert confirm =
  566. new Alert(AlertType.CONFIRMATION,
  567. "Are you sure you do that?!!!");
  568.  
  569. Optional<ButtonType> response = confirm.showAndWait();
  570.  
  571. if(response.isPresent() && response.get() == ButtonType.CANCEL) {
  572. System.out.println("You cancelled.");
  573.  
  574. } else {
  575.  
  576. if(showSummary) {
  577.  
  578. showSummary = false;
  579. textArea.setText("Show goal Summary set to " + showSummary);
  580.  
  581. } else {
  582.  
  583. showSummary = true;
  584. textArea.setText("Show goal Summary set to " + showSummary);
  585.  
  586. }
  587. }
  588. });
  589.  
  590. //IMPORT PLAYERS
  591. importPlayerListTab.setOnAction(i -> {
  592. try {
  593. readFile();
  594. } catch (FileNotFoundException e1) {
  595. // TODO Auto-generated catch block
  596. e1.printStackTrace();
  597. }
  598. });
  599.  
  600. //SAVES LIST AS IS
  601. savetab.setOnAction(l -> {
  602. //CREATE EMPTY FILE TO STORE PLAYER AND GOAL VALUES
  603. try {
  604. createEmptyFile();
  605. } catch (FileNotFoundException e1) {
  606. // TODO Auto-generated catch block
  607. e1.printStackTrace();
  608. }
  609. //SAVE PLAYER NAMES AND GOALS
  610. try {
  611. appendFile();
  612. } catch (IOException e1) {
  613. // TODO Auto-generated catch block
  614. e1.printStackTrace();
  615. }
  616. //CREATE EMPTY PREFERENCE FILE
  617. try {
  618. createEmptyPreferenceFile();
  619. } catch (FileNotFoundException e1) {
  620. // TODO Auto-generated catch block
  621. e1.printStackTrace();
  622. }
  623. //SAVE PREFERENCES TO FILE
  624. try {
  625. appendPreferenceFile();
  626. } catch (IOException e1) {
  627. // TODO Auto-generated catch block
  628. e1.printStackTrace();
  629. }
  630. textArea.setText("Preferences and Files saved. Thank you");
  631. });
  632.  
  633. //IMPORTS PREFERENCES
  634. importPrefencesTab.setOnAction(r -> {
  635. try {
  636. readPreferenceFile();
  637. } catch (FileNotFoundException e1) {
  638. // TODO Auto-generated catch block
  639. e1.printStackTrace();
  640. }
  641. });
  642.  
  643. //EXITS AND SAVES FILES
  644. exitMenuTab.setOnAction(f -> {
  645. try {
  646. createEmptyFile();
  647. } catch (FileNotFoundException e1) {
  648. // TODO Auto-generated catch block
  649. e1.printStackTrace();
  650. }
  651. //SAVE PLAYER NAMES AND GOALS
  652. try {
  653. appendFile();
  654. } catch (IOException e1) {
  655. // TODO Auto-generated catch block
  656. e1.printStackTrace();
  657. }
  658. //CREATE EMPTY PREFERENCE FILE
  659. try {
  660. createEmptyPreferenceFile();
  661. } catch (FileNotFoundException e1) {
  662. // TODO Auto-generated catch block
  663. e1.printStackTrace();
  664. }
  665. //SAVE PREFERENCES TO FILE
  666. try {
  667. appendPreferenceFile();
  668. } catch (IOException e1) {
  669. // TODO Auto-generated catch block
  670. e1.printStackTrace();
  671. }
  672.  
  673. try {
  674. createEmptyConnectedUsersFile();
  675. } catch (FileNotFoundException e2) {
  676. // TODO Auto-generated catch block
  677. e2.printStackTrace();
  678. }
  679.  
  680. try {
  681. appendConnectedUsersFile();
  682. } catch (IOException e1) {
  683. // TODO Auto-generated catch block
  684. e1.printStackTrace();
  685. }
  686. System.exit(0);
  687. });
  688.  
  689. updatePasswordTab.setOnAction(k -> {
  690. Label newPasswordLabel = new Label("Please enter your old password to continue");
  691. newPasswordLabel.setMinWidth(100);
  692. TextField newPasswordTextField = new TextField();
  693. newPasswordTextField.setMinWidth(100);
  694. //
  695. Button btnCheckPassword = new Button();
  696. //
  697. // Set the text, X & Y coordinates
  698. btnCheckPassword.setLayoutX(100);
  699. btnCheckPassword.setLayoutY(80);
  700. btnCheckPassword.setText("Enter");
  701. //
  702. VBox createPaneCheckPassword = new VBox(10, newPasswordLabel, newPasswordTextField);
  703. createPaneCheckPassword.getChildren().add(btnCheckPassword);
  704. createPaneCheckPassword.setAlignment(Pos.CENTER);
  705.  
  706. Stage stag4 = new Stage();
  707.  
  708. Scene sceneCheckPassword = new Scene(createPaneCheckPassword, 300, 250);
  709. stag4.setScene(sceneCheckPassword);
  710. stag4.show();
  711.  
  712. btnCheckPassword.setOnAction(p -> {
  713.  
  714. if(newPasswordTextField.getText().equals(password)) {
  715.  
  716. Label newPasswordEnterLabel = new Label("Please enter your new desired Password");
  717. newPasswordEnterLabel.setMinWidth(100);
  718. TextField newPasswordEnterTextField = new TextField();
  719. newPasswordEnterTextField.setMinWidth(100);
  720. //
  721. Button btnNewPassword = new Button();
  722. //
  723. // Set the text, X & Y coordinates
  724. btnNewPassword.setLayoutX(100);
  725. btnNewPassword.setLayoutY(80);
  726. btnNewPassword.setText("Enter");
  727. //
  728. VBox NewPane = new VBox(10, newPasswordEnterLabel, newPasswordEnterTextField);
  729. NewPane.getChildren().add(btnNewPassword);
  730. NewPane.setAlignment(Pos.CENTER);
  731.  
  732. Stage stag3 = new Stage();
  733.  
  734. Scene sceneNewPassword = new Scene(NewPane, 300, 250);
  735. stag3.setScene(sceneNewPassword);
  736. stag3.show();
  737.  
  738. stag4.close();
  739.  
  740. btnNewPassword.setOnAction(u -> {
  741. password = newPasswordEnterTextField.getText();
  742. System.out.print(password);
  743.  
  744. try {
  745. createBasicPasswordFile();
  746. } catch (FileNotFoundException e1) {
  747. // TODO Auto-generated catch block
  748. e1.printStackTrace();
  749. }
  750.  
  751. stag3.close();
  752. });
  753. } else {
  754. Stage dialogStageTwo = new Stage();
  755. dialogStage.initModality(Modality.WINDOW_MODAL);
  756.  
  757. VBox vboxTwo = new VBox(new Text("Incorrect Password"));
  758. vboxTwo.setAlignment(Pos.CENTER);
  759. vboxTwo.setPadding(new Insets(15));
  760.  
  761. //SENT TO VIP MENU
  762.  
  763. dialogStageTwo.setScene(new Scene(vboxTwo));
  764. dialogStageTwo.show();
  765. stag4.close();
  766. }
  767.  
  768.  
  769. });
  770. });
  771.  
  772. connectToVIPTab.setOnAction(x -> {
  773. ConnectLabel = new Label("Connect to a VIP:");
  774. ConnectListView = new ListView<String>();
  775.  
  776. for(int p = 0; p < playerListVIP.size(); p++) {
  777. //SoccerPlayer empty = new SoccerPlayer("");
  778. //playerList.add(empty);
  779. ConnectListView.getItems().addAll(playerListVIP.get(p).getName());
  780. //playerList.remove(empty);
  781. }
  782.  
  783. topBoxConnect = new HBox(60, ConnectLabel, ConnectListView);
  784. topBoxConnect.setPadding(new Insets(10, 20, 10, 20));
  785. topBoxConnect.setAlignment(Pos.CENTER);
  786.  
  787. //CHANGE METHOD FOR ACTION
  788.  
  789. submitButtonUpdate = new Button("SELECT");
  790. submitButtonUpdate.setOnAction(z -> connectToOtherUser());
  791.  
  792. sceneBoxUpdate = new VBox(topBoxConnect, submitButtonUpdate);
  793. sceneBoxUpdate.setAlignment(Pos.CENTER);
  794.  
  795. Scene sceneUpdate = new Scene(sceneBoxUpdate, 500, 400);
  796. updateStage.setScene(sceneUpdate);
  797. updateStage.show();
  798. });
  799.  
  800. disconnectVIPTab.setOnAction(b -> {
  801. ConnectLabel = new Label("Connect to a VIP:");
  802. ConnectListView = new ListView<String>();
  803. //
  804. for(int p = 0; p < connectedVIPS.size(); p++) {
  805. //SoccerPlayer empty = new SoccerPlayer("");
  806. //playerList.add(empty);
  807. ConnectListView.getItems().addAll(connectedVIPS.get(p).getName());
  808. //playerList.remove(empty);
  809. }
  810.  
  811. topBoxConnect = new HBox(60, ConnectLabel, ConnectListView);
  812. topBoxConnect.setPadding(new Insets(10, 20, 10, 20));
  813. topBoxConnect.setAlignment(Pos.CENTER);
  814.  
  815. //CHANGE METHOD FOR ACTION
  816.  
  817. submitButtonUpdate = new Button("SELECT");
  818. submitButtonUpdate.setOnAction(z -> disconnectFromOtherUser());
  819.  
  820. sceneBoxUpdate = new VBox(topBoxConnect, submitButtonUpdate);
  821. sceneBoxUpdate.setAlignment(Pos.CENTER);
  822.  
  823. Scene sceneUpdate = new Scene(sceneBoxUpdate, 500, 400);
  824. updateStage.setScene(sceneUpdate);
  825. updateStage.show();
  826. });
  827.  
  828. connectionsShowTab.setOnAction(w -> {
  829.  
  830. String totalConnections = "";
  831.  
  832. for(int t = 0; t < connectedVIPS.size(); t++) {
  833. totalConnections += connectedVIPS.get(t).getName() + "\n";
  834. //textArea.setText(connectedVIPS.get(t).getName());
  835. }
  836.  
  837. textArea.setText(totalConnections);
  838.  
  839. });
  840.  
  841. saveVIPConnectionList.setOnAction(f -> {
  842.  
  843. try {
  844. createEmptyConnectedUsersFile();
  845. } catch (FileNotFoundException e2) {
  846. // TODO Auto-generated catch block
  847. e2.printStackTrace();
  848. }
  849.  
  850. try {
  851. appendConnectedUsersFile();
  852. } catch (IOException e1) {
  853. // TODO Auto-generated catch block
  854. e1.printStackTrace();
  855. }
  856. });
  857.  
  858. //ADDS TABS TO EACH MENU ITEM
  859. fileTab.getItems().addAll(
  860. importPlayerListTab, importPrefencesTab, savetab, exitMenuTab
  861. );
  862.  
  863. playerListTab.getItems().addAll(
  864. createNewListTab, viewPlayerListTab, updatePlayerListTab, removePlayersTab
  865. );
  866.  
  867. goalListTab.getItems().addAll(
  868. viewGoalsTab, addGoalsTab
  869. );
  870.  
  871. preferencesTab.getItems().addAll(
  872. viewPreferencesTab, changeGoalSortTab, changeNameSortTab, changeSummaryTab, updatePasswordTab
  873. );
  874.  
  875. connectionsTab.getItems().addAll(
  876. connectionsShowTab, connectToVIPTab, disconnectVIPTab, saveVIPConnectionList
  877. );
  878.  
  879.  
  880. // Add menus to menu bar
  881. mainMenu.getMenus().addAll(fileTab, playerListTab, goalListTab, preferencesTab, connectionsTab);
  882.  
  883. // Add menu bar to Pane
  884. pane.getChildren().add(mainMenu);
  885. pane.getChildren().add(textArea);
  886.  
  887. } else {
  888.  
  889. //NON VIP - LESS OPTIONS TO DO
  890.  
  891. Text textArea = new Text("");
  892.  
  893. // Create Pane to host UI elements
  894. VBox pane = new VBox();
  895.  
  896. // Create menu bar to host menu items
  897. MenuBar mainMenu = new MenuBar();
  898.  
  899. // Create new menus to the bar
  900. Menu fileTab = new Menu("File");
  901.  
  902. javafx.scene.control.MenuItem importPlayerListTab = new javafx.scene.control.MenuItem("Import Player List");
  903. javafx.scene.control.MenuItem importPrefencesTab = new javafx.scene.control.MenuItem("Import Preferences");
  904. javafx.scene.control.MenuItem savetab = new javafx.scene.control.MenuItem("Save All");
  905. javafx.scene.control.MenuItem exitMenuTab = new javafx.scene.control.MenuItem("Exit");
  906.  
  907. Menu playerListTab = new Menu("Players");
  908.  
  909. javafx.scene.control.MenuItem createNewListTab = new javafx.scene.control.MenuItem("Create New List");
  910. javafx.scene.control.MenuItem viewPlayerListTab = new javafx.scene.control.MenuItem("View");
  911. javafx.scene.control.MenuItem updatePlayerListTab = new javafx.scene.control.MenuItem("Update Players");
  912. javafx.scene.control.MenuItem removePlayersTab = new javafx.scene.control.MenuItem("Remove Players");
  913.  
  914. Menu goalListTab = new Menu("Goal List");
  915.  
  916. javafx.scene.control.MenuItem viewGoalsTab = new javafx.scene.control.MenuItem("View");
  917. javafx.scene.control.MenuItem addGoalsTab = new javafx.scene.control.MenuItem("Add Goals");
  918.  
  919. Menu preferencesTab = new Menu("Prefences");
  920.  
  921. javafx.scene.control.MenuItem viewPreferencesTab = new javafx.scene.control.MenuItem("View");
  922. javafx.scene.control.MenuItem changeGoalSortTab = new javafx.scene.control.MenuItem("Change Goal Sort");
  923. javafx.scene.control.MenuItem changeNameSortTab = new javafx.scene.control.MenuItem("Change Name Sort");
  924. javafx.scene.control.MenuItem changeSummaryTab = new javafx.scene.control.MenuItem("Change Summary Display");
  925.  
  926. Scene sceneMain = new Scene(pane, 500, 650);
  927. primaryStage.setScene(sceneMain);
  928. primaryStage.show();
  929.  
  930. Stage dialogStage = new Stage();
  931. dialogStage.initModality(Modality.WINDOW_MODAL);
  932.  
  933. VBox vbox = new VBox(new Text("Sent to the Regular Menu"));
  934. vbox.setAlignment(Pos.CENTER);
  935. vbox.setPadding(new Insets(15));
  936.  
  937. dialogStage.setScene(new Scene(vbox));
  938. dialogStage.show();
  939.  
  940. createNewListTab.setOnAction(r -> {
  941. if(listCreated == false) {
  942. Label playerAmountLabel = new Label("Please enter the number of players that would like to track 5 max");
  943. playerAmountLabel.setMinWidth(100);
  944. TextField playerAmountTextField = new TextField();
  945. playerAmountTextField.setMinWidth(100);
  946. //
  947. Button btnCreateList = new Button();
  948. //
  949. // Set the text, X & Y coordinates
  950. btnCreateList.setLayoutX(100);
  951. btnCreateList.setLayoutY(80);
  952. btnCreateList.setText("Enter");
  953. //
  954. VBox createPane = new VBox(10, playerAmountLabel, playerAmountTextField);
  955. createPane.getChildren().add(btnCreateList);
  956. createPane.setAlignment(Pos.CENTER);
  957.  
  958. Stage stag2 = new Stage();
  959.  
  960. Scene sceneCreatePlayerAmount = new Scene(createPane, 300, 250);
  961. stag2.setScene(sceneCreatePlayerAmount);
  962. stag2.show();
  963.  
  964. btnCreateList.setOnAction(a -> {
  965.  
  966. amountOfPlayers = Integer.parseInt(playerAmountTextField.getText());
  967. System.out.println(amountOfPlayers);
  968. stag2.close();
  969.  
  970. //CREATES EMPTY FILE TO BEGIN STORING DATA IF FILE DOES NOT EXIST
  971. try {
  972. createEmptyFile();
  973. } catch (FileNotFoundException e1) {
  974. // TODO Auto-generated catch block
  975. e1.printStackTrace();
  976. }
  977.  
  978. if (amountOfPlayers <=5 && amountOfPlayers >0) {
  979.  
  980. //WARNING
  981. System.out.println("**** CAUTION ****\nCreating Players with duplicate names will\ncause your list to be deleted.\n");
  982. Stage dialogStageWarning = new Stage();
  983. //dialogStageWarning.initModality(Modality.WINDOW_MODAL);
  984.  
  985. VBox vboxWarning = new VBox(new Text("**** CAUTION ****\nCreating Players with duplicate names will\ncause your list to be deleted.\n"));
  986. vboxWarning.setAlignment(Pos.CENTER);
  987. vboxWarning.setPadding(new Insets(15));
  988.  
  989. dialogStageWarning.setScene(new Scene(vboxWarning));
  990. dialogStageWarning.show();
  991.  
  992. //CREATES PLAYER OBJECTS
  993. for (int i =0; i < amountOfPlayers; i++) {
  994. Label playerNameLabel = new Label("Please enter the name of player ");
  995. playerNameLabel.setMinWidth(100);
  996. TextField playerNameTextField = new TextField();
  997. playerNameTextField.setMinWidth(100);
  998. //
  999. Button btnPlayerName = new Button();
  1000. //
  1001. // Set the text, X & Y coordinates
  1002. btnPlayerName.setLayoutX(100);
  1003. btnPlayerName.setLayoutY(80);
  1004. btnPlayerName.setText("Enter");
  1005. //
  1006. VBox createPlayerNamePane = new VBox(10, playerNameLabel, playerNameTextField);
  1007. createPlayerNamePane.getChildren().add(btnPlayerName);
  1008.  
  1009. Scene sceneCreatePlayerName = new Scene(createPlayerNamePane, 300, 250);
  1010. Stage playerNameSet = new Stage();
  1011. playerNameSet.setScene(sceneCreatePlayerName);
  1012. playerNameSet.show();
  1013.  
  1014. btnPlayerName.setOnAction(v -> {
  1015.  
  1016. playerNameSet.close();
  1017. String playerName = playerNameTextField.getText();
  1018. System.out.println(playerName);
  1019. SoccerPlayer player = new SoccerPlayer(playerName);
  1020. playerList.add(player);
  1021.  
  1022. });
  1023.  
  1024. }
  1025.  
  1026. //LIST CREATED
  1027. listCreated = true;
  1028. //CHECK DUPLICATE VALUES
  1029. checkDuplicate();
  1030.  
  1031. } else {
  1032. //CATCH
  1033. textArea.setText("You must enter a number between 0 and 5");
  1034. }
  1035. });
  1036. } else {
  1037. textArea.setText("You must delete a list first");
  1038. }
  1039. });
  1040.  
  1041. viewPlayerListTab.setOnAction(r -> {
  1042.  
  1043. if(listCreated == true) {
  1044. textArea.setText("");
  1045. String a = "";
  1046. SoccerPlayer empty = new SoccerPlayer("");
  1047. playerList.add(empty);
  1048. for(int u =0; u < amountOfPlayers; u++) {
  1049. a = a + playerList.get(u).getName() + "\n";
  1050. //textArea.setText("\n " + playerList.get(u).getName());
  1051. //pane.getChildren().add(new Text(playerList.get(u).getName()));
  1052. }
  1053. textArea.setText(a);
  1054. playerList.remove(empty);
  1055. } else {
  1056. textArea.setText("You must create a list first");
  1057.  
  1058. }
  1059. });
  1060.  
  1061. updatePlayerListTab.setOnAction(x -> {
  1062. if(listCreated == true) {
  1063. UpdateLabel = new Label("Choose a Player:");
  1064. UpdateListView = new ListView<String>();
  1065. for(int p = 0; p < amountOfPlayers; p++) {
  1066. SoccerPlayer empty = new SoccerPlayer("");
  1067. playerList.add(empty);
  1068. UpdateListView.getItems().addAll(playerList.get(p).getName());
  1069. playerList.remove(empty);
  1070. }
  1071.  
  1072. topBoxUpdate = new HBox(60, UpdateLabel, UpdateListView);
  1073. topBoxUpdate.setPadding(new Insets(10, 20, 10, 20));
  1074. topBoxUpdate.setAlignment(Pos.CENTER);
  1075.  
  1076. submitButtonUpdate = new Button("SELECT");
  1077. submitButtonUpdate.setOnAction(z -> updatePlayer());
  1078.  
  1079. sceneBoxUpdate = new VBox(topBoxUpdate, submitButtonUpdate);
  1080. sceneBoxUpdate.setAlignment(Pos.CENTER);
  1081.  
  1082. Scene sceneUpdate = new Scene(sceneBoxUpdate, 500, 400);
  1083. updateStage.setScene(sceneUpdate);
  1084. updateStage.show();
  1085. } else {
  1086. textArea.setText("You must create a list first");
  1087. }
  1088. });
  1089.  
  1090. removePlayersTab.setOnAction(y -> {
  1091. if(listCreated == true) {
  1092. UpdateLabel = new Label("Choose a Player:");
  1093. UpdateListView = new ListView<String>();
  1094. for(int p = 0; p < amountOfPlayers; p++) {
  1095. UpdateListView.getItems().addAll(playerList.get(p).getName());
  1096. }
  1097.  
  1098. UpdateListView.getItems().addAll("Clear all");
  1099.  
  1100. topBoxUpdate = new HBox(60, UpdateLabel, UpdateListView);
  1101. topBoxUpdate.setPadding(new Insets(10, 20, 10, 20));
  1102. topBoxUpdate.setAlignment(Pos.CENTER);
  1103.  
  1104. submitButtonUpdate = new Button("SELECT");
  1105. submitButtonUpdate.setOnAction(z -> removePlayer());
  1106.  
  1107. sceneBoxUpdate = new VBox(topBoxUpdate, submitButtonUpdate);
  1108. sceneBoxUpdate.setAlignment(Pos.CENTER);
  1109.  
  1110. Scene sceneUpdate = new Scene(sceneBoxUpdate, 500, 400);
  1111. updateStage.setScene(sceneUpdate);
  1112. updateStage.show();
  1113. } else {
  1114. textArea.setText("You must create a list first");
  1115. }
  1116. });
  1117.  
  1118. viewGoalsTab.setOnAction(b -> {
  1119. if(listCreated == true) {
  1120. if(namesOrderAscending) {
  1121. sortNames();
  1122. } else {
  1123. sortNamesDescending();
  1124. }
  1125.  
  1126. if(goalsSortDescending) {
  1127. sortGoals();
  1128. } else {
  1129. sortGoalsAscending();
  1130. }
  1131.  
  1132.  
  1133. textArea.setText("");
  1134. String a = "";
  1135. SoccerPlayer empty = new SoccerPlayer("");
  1136. playerList.add(empty);
  1137. for(int u =0; u < amountOfPlayers; u++) {
  1138. a = a + playerList.get(u).getName() + " " + playerList.get(u).getgoals() + "\n";
  1139. //textArea.setText("\n " + playerList.get(u).getName());
  1140. //pane.getChildren().add(new Text(playerList.get(u).getName()));
  1141. }
  1142.  
  1143. if(showSummary) {
  1144. a = a + "\n" + showPlayerSummary();
  1145. } else {
  1146. //nothing shown
  1147. }
  1148.  
  1149. textArea.setText(a);
  1150. playerList.remove(empty);
  1151. goalstotal = 0;
  1152. } else {
  1153. textArea.setText("you must make a list first");
  1154.  
  1155. }
  1156. });
  1157.  
  1158. addGoalsTab.setOnAction(x -> {
  1159. if(listCreated == true) {
  1160. UpdateLabel = new Label("Choose a Player:");
  1161. UpdateListView = new ListView<String>();
  1162. for(int p = 0; p < amountOfPlayers; p++) {
  1163. SoccerPlayer empty = new SoccerPlayer("");
  1164. playerList.add(empty);
  1165. UpdateListView.getItems().addAll(playerList.get(p).getName());
  1166. playerList.remove(empty);
  1167. }
  1168.  
  1169. topBoxUpdate = new HBox(60, UpdateLabel, UpdateListView);
  1170. topBoxUpdate.setPadding(new Insets(10, 20, 10, 20));
  1171. topBoxUpdate.setAlignment(Pos.CENTER);
  1172.  
  1173. submitButtonUpdate = new Button("SELECT");
  1174. submitButtonUpdate.setOnAction(z -> updatePlayerGoals());
  1175.  
  1176. sceneBoxUpdate = new VBox(topBoxUpdate, submitButtonUpdate);
  1177. sceneBoxUpdate.setAlignment(Pos.CENTER);
  1178.  
  1179. Scene sceneUpdate = new Scene(sceneBoxUpdate, 500, 400);
  1180. updateStage.setScene(sceneUpdate);
  1181. updateStage.show();
  1182. } else {
  1183. pane.getChildren().add(new Text("You must make a list first"));
  1184. }
  1185. });
  1186.  
  1187. viewPreferencesTab.setOnAction(d -> {
  1188.  
  1189. textArea.setText("");
  1190. String a = "1. Goals sort order " + "[" + goalsSortStatus + "]"
  1191. + "\n2. Names sort order " + "[" + namesSortStatus + "]" +
  1192. "\n3. Show goal summary " + "[" + showSummary + "]"
  1193. + "\n4. Return to main menu\n";
  1194.  
  1195. textArea.setText(a);
  1196. });
  1197.  
  1198. changeGoalSortTab.setOnAction(w -> {
  1199. textArea.setText("This feature is only allowed for VIP users, please\n contact Sassy Maven is you want to purchase the VIP verison\nof this program");
  1200. });
  1201.  
  1202. changeNameSortTab.setOnAction(c -> {
  1203. textArea.setText("This feature is only allowed for VIP users, please\n contact Sassy Maven is you want to purchase the VIP verison\nof this program");
  1204. });
  1205.  
  1206. changeSummaryTab.setOnAction(q -> {
  1207. textArea.setText("This feature is only allowed for VIP users, please\n contact Sassy Maven is you want to purchase the VIP verison\nof this program");
  1208. });
  1209.  
  1210. importPlayerListTab.setOnAction(i -> {
  1211. try {
  1212. readFile();
  1213. } catch (FileNotFoundException e1) {
  1214. // TODO Auto-generated catch block
  1215. e1.printStackTrace();
  1216. }
  1217. });
  1218.  
  1219. importPrefencesTab.setOnAction(s -> {
  1220. textArea.setText("This feature is only allowed for VIP users, please\n contact Sassy Maven is you want to purchase the VIP verison\nof this program");
  1221. });
  1222.  
  1223. savetab.setOnAction(l -> {
  1224. //CREATE EMPTY FILE TO STORE PLAYER AND GOAL VALUES
  1225. try {
  1226. createEmptyFile();
  1227. } catch (FileNotFoundException e1) {
  1228. // TODO Auto-generated catch block
  1229. e1.printStackTrace();
  1230. }
  1231. //SAVE PLAYER NAMES AND GOALS
  1232. try {
  1233. appendFile();
  1234. } catch (IOException e1) {
  1235. // TODO Auto-generated catch block
  1236. e1.printStackTrace();
  1237. }
  1238.  
  1239. textArea.setText("Files saved. Thank you");
  1240. });
  1241.  
  1242. importPrefencesTab.setOnAction(r -> {
  1243. textArea.setText("This feature is only allowed for VIP users, please\n contact Sassy Maven is you want to purchase the VIP verison\nof this program");
  1244. });
  1245.  
  1246. exitMenuTab.setOnAction(f -> {
  1247. try {
  1248. createEmptyFile();
  1249. } catch (FileNotFoundException e1) {
  1250. // TODO Auto-generated catch block
  1251. e1.printStackTrace();
  1252. }
  1253. //SAVE PLAYER NAMES AND GOALS
  1254. try {
  1255. appendFile();
  1256. } catch (IOException e1) {
  1257. // TODO Auto-generated catch block
  1258. e1.printStackTrace();
  1259. }
  1260.  
  1261. System.exit(0);
  1262. });
  1263.  
  1264. fileTab.getItems().addAll(
  1265. importPlayerListTab, importPrefencesTab, savetab, exitMenuTab
  1266. );
  1267.  
  1268. playerListTab.getItems().addAll(
  1269. createNewListTab, viewPlayerListTab, updatePlayerListTab, removePlayersTab
  1270. );
  1271.  
  1272. goalListTab.getItems().addAll(
  1273. viewGoalsTab, addGoalsTab
  1274. );
  1275.  
  1276. preferencesTab.getItems().addAll(
  1277. viewPreferencesTab, changeGoalSortTab, changeNameSortTab, changeSummaryTab
  1278. );
  1279.  
  1280.  
  1281. // Add menus to menu bar
  1282. mainMenu.getMenus().addAll(fileTab, playerListTab, goalListTab, preferencesTab);
  1283.  
  1284. // Add menu bar to Pane
  1285. pane.getChildren().add(mainMenu);
  1286. pane.getChildren().add(textArea);
  1287.  
  1288.  
  1289.  
  1290. }
  1291.  
  1292. if(passwordEntry.equals("#ChelseaIsTheBest")) {
  1293. Label initialPasswordReset = new Label("Please enter a new password");
  1294. initialPasswordReset.setMinWidth(100);
  1295. TextField initialPasswordResetTextField = new TextField();
  1296. initialPasswordResetTextField.setMinWidth(100);
  1297. //
  1298. Button btnInitialPasswordReset = new Button();
  1299. //
  1300. // Set the text, X & Y coordinates
  1301. btnInitialPasswordReset.setLayoutX(100);
  1302. btnInitialPasswordReset.setLayoutY(80);
  1303. btnInitialPasswordReset.setText("Enter");
  1304. //
  1305. VBox initialPasswordResetPane = new VBox(10, initialPasswordReset, initialPasswordResetTextField);
  1306. initialPasswordResetPane.setAlignment(Pos.CENTER);
  1307. initialPasswordResetPane.getChildren().add(btnInitialPasswordReset);
  1308.  
  1309. Stage initialPasswordResetStage = new Stage();
  1310.  
  1311. Scene sceneInitialPassword = new Scene(initialPasswordResetPane, 300, 250);
  1312. initialPasswordResetStage.setScene(sceneInitialPassword);
  1313. initialPasswordResetStage.show();
  1314.  
  1315. btnInitialPasswordReset.setOnAction(y -> {
  1316. initialPasswordResetStage.close();
  1317. password = initialPasswordResetTextField.getText();
  1318.  
  1319. Stage dialogStage5 = new Stage();
  1320. dialogStage5.initModality(Modality.WINDOW_MODAL);
  1321.  
  1322. VBox vboxReset = new VBox(new Text("Password Successfully Changed"));
  1323. vboxReset.setAlignment(Pos.CENTER);
  1324. vboxReset.setPadding(new Insets(15));
  1325.  
  1326. try {
  1327. createBasicPasswordFile();
  1328. } catch (FileNotFoundException e1) {
  1329. // TODO Auto-generated catch block
  1330. e1.printStackTrace();
  1331. }
  1332.  
  1333. //SENT TO VIP MENU
  1334.  
  1335. dialogStage5.setScene(new Scene(vboxReset));
  1336. dialogStage5.show();
  1337. });
  1338. }
  1339. });
  1340. }
  1341.  
  1342. public static void main(String[] args) {
  1343. try {
  1344. readPasswordFile();
  1345. } catch (FileNotFoundException e) {
  1346. try {
  1347. createBasicPasswordFile();
  1348. } catch (FileNotFoundException e1) {
  1349. // TODO Auto-generated catch block
  1350. e1.printStackTrace();
  1351. }
  1352. }
  1353.  
  1354. for(User u:SassyUserProvider.getInstance().getUsers())
  1355. {
  1356.  
  1357. playerListVIP.add(u);
  1358.  
  1359. }
  1360.  
  1361. try {
  1362. readConnectedUsersFile();
  1363. } catch (FileNotFoundException e) {
  1364. // TODO Auto-generated catch block
  1365. e.printStackTrace();
  1366. }
  1367.  
  1368. Application.launch(args);
  1369. }
  1370.  
  1371. public static void updatePlayer() {
  1372.  
  1373. String selectedPlayer = (UpdateListView.getSelectionModel().getSelectedItem() == null) ? "C#" : UpdateListView.getSelectionModel().getSelectedItem();
  1374. System.out.println("You've selected " + selectedPlayer);
  1375.  
  1376. Label updatePlayerLabel = new Label("Please enter the new name for this Player");
  1377. updatePlayerLabel.setMinWidth(100);
  1378. TextField updatePlayerTextField = new TextField();
  1379. updatePlayerTextField.setMinWidth(100);
  1380. //
  1381. Button btnUpdatePlayer = new Button();
  1382. //
  1383. // Set the text, X & Y coordinates
  1384. btnUpdatePlayer.setLayoutX(100);
  1385. btnUpdatePlayer.setLayoutY(80);
  1386. btnUpdatePlayer.setText("Enter");
  1387. //
  1388. VBox UpdatePlayerPane = new VBox(10, updatePlayerLabel, updatePlayerTextField);
  1389. UpdatePlayerPane.getChildren().add(btnUpdatePlayer);
  1390.  
  1391. Scene sceneCreatePlayerAmount = new Scene(UpdatePlayerPane, 300, 250);
  1392. updateStage.setScene(sceneCreatePlayerAmount);
  1393. updateStage.show();
  1394.  
  1395. btnUpdatePlayer.setOnAction(w -> {
  1396. updateStage.close();
  1397. playerList.get(UpdateListView.getItems().indexOf(selectedPlayer)).setName(updatePlayerTextField.getText());
  1398. playerList.get(UpdateListView.getItems().indexOf(selectedPlayer)).settGoals(0);
  1399. });
  1400.  
  1401. }
  1402.  
  1403. public static void removePlayer() {
  1404.  
  1405. updateStage.close();
  1406. if(UpdateListView.getSelectionModel().getSelectedItem() == "Clear all") {
  1407. playerList.clear();
  1408. listCreated = false;
  1409. } else {
  1410. SoccerPlayer empty = new SoccerPlayer("");
  1411. playerList.add(empty);
  1412. String selectedPlayer = (UpdateListView.getSelectionModel().getSelectedItem() == null) ? "C#" : UpdateListView.getSelectionModel().getSelectedItem();
  1413. playerList.remove(UpdateListView.getItems().indexOf(selectedPlayer));
  1414. playerList.remove(empty);
  1415. }
  1416.  
  1417. }
  1418.  
  1419. public static void updatePlayerGoals() {
  1420. String selectedPlayer = (UpdateListView.getSelectionModel().getSelectedItem() == null) ? "C#" : UpdateListView.getSelectionModel().getSelectedItem();
  1421. System.out.println("You've selected " + selectedPlayer);
  1422.  
  1423. Label updatePlayerLabel = new Label("Please enter the amount of goals you would like to add to this player");
  1424. updatePlayerLabel.setMinWidth(100);
  1425. TextField updatePlayerTextField = new TextField();
  1426. updatePlayerTextField.setMinWidth(100);
  1427. //
  1428. Button btnUpdatePlayer = new Button();
  1429. //
  1430. // Set the text, X & Y coordinates
  1431. btnUpdatePlayer.setLayoutX(100);
  1432. btnUpdatePlayer.setLayoutY(80);
  1433. btnUpdatePlayer.setText("Enter");
  1434. //
  1435. VBox UpdatePlayerPane = new VBox(10, updatePlayerLabel, updatePlayerTextField);
  1436. UpdatePlayerPane.getChildren().add(btnUpdatePlayer);
  1437.  
  1438. Scene sceneCreatePlayerAmount = new Scene(UpdatePlayerPane, 300, 250);
  1439. updateStage.setScene(sceneCreatePlayerAmount);
  1440. updateStage.show();
  1441.  
  1442. btnUpdatePlayer.setOnAction(w -> {
  1443. updateStage.close();
  1444. //playerList.get(UpdateListView.getItems().indexOf(selectedPlayer)).setName(updatePlayerTextField.getText());
  1445. playerList.get(UpdateListView.getItems().indexOf(selectedPlayer)).setGoals(Integer.parseInt(updatePlayerTextField.getText()));
  1446. });
  1447. }
  1448.  
  1449. public static void sortGoals() {
  1450.  
  1451. //SORT PLAYER GOALS BY DESCENDING VALUES
  1452. Collections.sort(playerList, new Comparator<SoccerPlayer>(){
  1453.  
  1454. //COMPARES NAMES
  1455. public int compare(SoccerPlayer o1, SoccerPlayer o2)
  1456. {
  1457. return o2.getgoals() - o1.getgoals();
  1458.  
  1459. }
  1460. });
  1461.  
  1462. }
  1463.  
  1464. public static void sortNames() {
  1465.  
  1466. //SORT NAMES ALPHABETICALLY
  1467. Collections.sort(playerList, new Comparator<SoccerPlayer>() {
  1468. public int compare(SoccerPlayer v1,SoccerPlayer v2) {
  1469. //RETURNS POSITIVE OR NEGATIVE VALUE
  1470. return v1.getName().compareTo(v2.getName());
  1471. }
  1472. });
  1473.  
  1474. }
  1475.  
  1476. public static void sortNamesExternal(int userID) {
  1477.  
  1478. //for(int s = 0; s < playerListVIP.get(userID - 1).getSassers().length; s++) {
  1479. //SORT NAMES ALPHABETICALLY
  1480. Arrays.sort(playerListVIP.get(userID - 1).getSassers(), new Comparator<Sasser>() {
  1481. public int compare(Sasser v1,Sasser v2) {
  1482. //RETURNS POSITIVE OR NEGATIVE VALUE
  1483. return v2.getName().compareTo(v1.getName());
  1484. }
  1485. });
  1486. //}
  1487.  
  1488. }
  1489.  
  1490. public static void sortNamesDescendingExternal(int userID) {
  1491. //for(int s = 0; s < playerListVIP.get(userID - 1).getSassers().length; s++) {
  1492. //SORT NAMES ALPHABETICALLY
  1493. Arrays.sort(playerListVIP.get(userID - 1).getSassers(), new Comparator<Sasser>() {
  1494. public int compare(Sasser v1,Sasser v2) {
  1495. //RETURNS POSITIVE OR NEGATIVE VALUE
  1496. return v1.getName().compareTo(v2.getName());
  1497. }
  1498. });
  1499. // }
  1500. }
  1501.  
  1502. public static void sortGoalsAscending() {
  1503. //SORTS GOALS BY ASCENDING VALUE
  1504. Collections.sort(playerList, new Comparator<SoccerPlayer>(){
  1505.  
  1506. public int compare(SoccerPlayer o1, SoccerPlayer o2)
  1507. {
  1508. //RETURNS POSITIVE OR NEGATIVE INT
  1509. return Integer.compare(o1.getgoals(), o2.getgoals());
  1510.  
  1511. }
  1512. });
  1513. }
  1514.  
  1515. public static void sortNamesDescending() {
  1516. //SORTS NAMES IN DESCENDING VALUE BY REVERSING ALPHABETICALLY NAMES
  1517. sortNames();
  1518. Collections.reverse(playerList);
  1519. }
  1520.  
  1521. public static String showPlayerSummary() {
  1522.  
  1523. //SHOWS PLAYERS GOAL SUMMARY
  1524.  
  1525. for (int u = 0; u < playerList.size(); u++) {
  1526. goalstotal += playerList.get(u).getgoals();
  1527. }
  1528.  
  1529. //SHOWS GOAL SUMMARY
  1530.  
  1531. System.out.println("\n" + playerList.get(topPlayer()).getName() + " is the top scorer\nAverage number of goals is " + average(goalstotal, playerList.size()) +
  1532. "\nThe total number of goals is " + goalstotal);
  1533.  
  1534. //SETS TOTAL GOALS TO ZERO TO PREVENT EXTRA ADDITION EACH TIME
  1535.  
  1536.  
  1537. return "\n" + playerList.get(topPlayer()).getName() + " is the top scorer\nAverage number of goals is " + average(goalstotal, playerList.size()) +
  1538. "\nThe total number of goals is " + goalstotal;
  1539.  
  1540. }
  1541.  
  1542. public static String showPlayerSummaryExternal(int userID) {
  1543. //SHOWS PLAYERS GOAL SUMMARY
  1544.  
  1545. for(int e = 0; e < playerListVIP.get(userID - 1).getSassers().length; e++) {
  1546. goalstotalExternal += playerListVIP.get(userID - 1).getSassers()[e].getGoals();
  1547. }
  1548.  
  1549.  
  1550. //SETS TOTAL GOALS TO ZERO TO PREVENT EXTRA ADDITION EACH TIME
  1551.  
  1552. return "\n" + playerListVIP.get(userID - 1).getSassers()[topPlayerExternal(userID - 1)].getName() + " is the top scorer\nAverage number of goals is " + average(goalstotalExternal, playerListVIP.get(userID - 1).getSassers().length) +
  1553. "\nThe total number of goals is " + goalstotalExternal + "\n";
  1554. }
  1555.  
  1556. public static void sortGoalsExternal(int userID) {
  1557. //for(int s = 0; s < playerListVIP.get(userID - 1).getSassers().length; s++) {
  1558. Arrays.sort(playerListVIP.get(userID - 1).getSassers(), new Comparator<Sasser>(){
  1559.  
  1560. //COMPARES NAMES
  1561.  
  1562. public int compare(Sasser o1, Sasser o2)
  1563. {
  1564. return o2.getGoals() - o1.getGoals();
  1565.  
  1566. }
  1567.  
  1568. });
  1569. //}
  1570. }
  1571.  
  1572. public static void sortGoalsAscendingExternal(int userID) {
  1573. //SORTS GOALS BY ASCENDING VALUE
  1574. //for(int s = 0; s < playerListVIP.get(userID - 1).getSassers().length; s++) {
  1575. Arrays.sort(playerListVIP.get(userID - 1).getSassers(), new Comparator<Sasser>(){
  1576.  
  1577. public int compare(Sasser o1, Sasser o2)
  1578. {
  1579. //RETURNS POSITIVE OR NEGATIVE INT
  1580. return Integer.compare(o1.getGoals(), o2.getGoals());
  1581.  
  1582. }
  1583. });
  1584. //}
  1585. }
  1586.  
  1587. public static double average(int a, int b) {
  1588. //GETS AVERAGE OF ALL GOALS
  1589. double avg = 0;
  1590.  
  1591. avg = (double) a / b;
  1592. return avg;
  1593.  
  1594. }
  1595.  
  1596. public static int topPlayer() {
  1597. //DETERMIENS TOP PLAYER WITH MOST GOALS
  1598. int top = 0;
  1599.  
  1600. if (goalsSortDescending == false) {
  1601. top = (amountOfPlayers - 1);
  1602. } else {
  1603. top = 0;
  1604. }
  1605. return top;
  1606. }
  1607.  
  1608. public static int topPlayerExternal(int userID) {
  1609. int top = 0;
  1610.  
  1611. if (goalsSortDescending == false) {
  1612. top = (playerListVIP.get(userID).getSassers().length - 1);
  1613. } else {
  1614. top = 0;
  1615. }
  1616. return top;
  1617. }
  1618.  
  1619. public static void checkDuplicate() {
  1620.  
  1621. //CREATE A NEW HASHSET
  1622. Set<String> uniquUsers = new HashSet<String>();
  1623.  
  1624. for (int g = 0; g < playerList.size(); g++) {
  1625. //ADDS A PLAYER TO THE SET IF THE NAME IS DUPLICATED IN THE ARRAY
  1626. if (!uniquUsers.add(playerList.get(g).getName())) {
  1627.  
  1628. //SETS THE NAME TO DUPLICATE, DOESN'T AFFECT PROGRAM OUTPUT
  1629. //playerList.get(g).getName() = "Duplicate";
  1630. System.out.println("Sorry no duplicate names. Your list will be deleted.\n");
  1631. playerList.clear();
  1632. listCreated = false;
  1633. //SETS UP FOR A NEW ARRAY TO BE CREATED
  1634. //playerListStatus = false;
  1635.  
  1636. }
  1637. }
  1638.  
  1639. }
  1640.  
  1641. public static void readFile() throws FileNotFoundException {
  1642.  
  1643. Alert confirm =
  1644. new Alert(AlertType.CONFIRMATION,
  1645. "Are you sure you do that?!!!");
  1646.  
  1647. Optional<ButtonType> response = confirm.showAndWait();
  1648.  
  1649. if(response.isPresent() && response.get() == ButtonType.CANCEL) {
  1650. System.out.println("You cancelled.");
  1651.  
  1652. } else {
  1653.  
  1654.  
  1655. Label playerAmountLabel = new Label("Please enter the number of players that would like to track");
  1656. playerAmountLabel.setMinWidth(100);
  1657. TextField playerAmountTextField = new TextField();
  1658. playerAmountTextField.setMinWidth(100);
  1659. //
  1660. Button btnCreateList = new Button();
  1661. //
  1662. // Set the text, X & Y coordinates
  1663. btnCreateList.setLayoutX(100);
  1664. btnCreateList.setLayoutY(80);
  1665. btnCreateList.setText("Enter");
  1666. //
  1667. VBox createPane = new VBox(10, playerAmountLabel, playerAmountTextField);
  1668. createPane.getChildren().add(btnCreateList);
  1669.  
  1670. Stage stag2 = new Stage();
  1671.  
  1672. btnCreateList.setOnAction(t -> {
  1673. stag2.close();
  1674.  
  1675. File myFile = new File("SoccerPlayerData.txt");
  1676. Scanner inputReader = null;
  1677. try {
  1678. inputReader = new Scanner(myFile);
  1679. } catch (FileNotFoundException e) {
  1680. // TODO Auto-generated catch block
  1681. e.printStackTrace();
  1682. }
  1683.  
  1684. amountOfPlayers = Integer.parseInt(playerAmountTextField.getText());
  1685.  
  1686. for(int p = 0; p < amountOfPlayers; p++) {
  1687. SoccerPlayer player = new SoccerPlayer("");
  1688. playerList.add(player);
  1689. }
  1690.  
  1691. for(int f = 0; f < amountOfPlayers; f++) {
  1692.  
  1693. //READS NAME LINE
  1694. String nameLine = inputReader.nextLine();
  1695.  
  1696. //SETS NAME VALUE
  1697. playerList.get((f)).setName(nameLine);
  1698.  
  1699. //READS INT LINE
  1700. String goalsLine = inputReader.nextLine();
  1701.  
  1702. //SETS GOAL VALUE
  1703. playerList.get((f)).settGoals(Integer.parseInt(goalsLine));
  1704.  
  1705. //FILE CHECK
  1706. if(f == 0 && nameLine.length() == 0) {
  1707. f = 8;
  1708. System.out.println("A file with saved preferences does not yet exist");
  1709. listCreated = false;
  1710. }
  1711.  
  1712. //DETERMIENS THAT THE LIST IS TRUE
  1713. listCreated = true;
  1714.  
  1715. }
  1716. inputReader.close();
  1717.  
  1718. });
  1719. Scene sceneCreatePlayerAmount = new Scene(createPane, 300, 250);
  1720. stag2.setScene(sceneCreatePlayerAmount);
  1721. stag2.show();
  1722.  
  1723.  
  1724.  
  1725. }
  1726.  
  1727. }
  1728.  
  1729. public static void appendFile() throws IOException {
  1730.  
  1731. //STORES DATA TO THE FILE
  1732. FileWriter fwriter = new FileWriter("SoccerPlayerData.txt");
  1733. PrintWriter outputWriter = new PrintWriter(fwriter);
  1734.  
  1735. //STORES DATA TO FILE
  1736. for(int f = 0; f < (playerList.size()); f++) {
  1737. outputWriter.println(playerList.get(f).getName() /*+ " " + playerList.get(f).getgoals()*/);
  1738. outputWriter.println(playerList.get(f).getgoals());
  1739. }
  1740.  
  1741. //CLOSE IT FOR GOOD MEASURES
  1742. outputWriter.close();
  1743.  
  1744. }
  1745.  
  1746. public static void createEmptyFile() throws FileNotFoundException {
  1747.  
  1748. //CREATES EMPTY TEXT FILE FOR PLAYER DATA STORAGE
  1749. PrintWriter outputWriter = new PrintWriter("SoccerPlayerData.txt");
  1750. }
  1751.  
  1752. public static void createBasicPasswordFile() throws FileNotFoundException {
  1753.  
  1754. //CREATES EMPTY TEXT FILE FOR PLAYER DATA STORAGE
  1755. PrintWriter outputWriter = new PrintWriter("SassySoccerAppPassword.txt");
  1756. try {
  1757. FileWriter fwriter = new FileWriter("SassySoccerAppPassword.txt");
  1758. PrintWriter outputWriterPassword = new PrintWriter(fwriter);
  1759. outputWriterPassword.println(password);
  1760.  
  1761. outputWriterPassword.close();
  1762.  
  1763. } catch (IOException e) {
  1764. // TODO Auto-generated catch block
  1765. e.printStackTrace();
  1766. }
  1767. }
  1768.  
  1769. public static void appendPasswordFile() throws IOException {
  1770.  
  1771. //APPENDS PREFERENCE FILES
  1772. FileWriter fwriter = new FileWriter("SassySoccerAppPassword.txt");
  1773. PrintWriter outputWriterPassword = new PrintWriter(fwriter);
  1774.  
  1775. outputWriterPassword.println(password);
  1776.  
  1777. outputWriterPassword.close();
  1778. }
  1779.  
  1780. public static void readPasswordFile() throws FileNotFoundException {
  1781. File myFile = new File("SassySoccerAppPassword.txt");
  1782. Scanner inputReaders = new Scanner(myFile);
  1783.  
  1784. String passwordFromFile = inputReaders.nextLine();
  1785. password = passwordFromFile;
  1786. }
  1787.  
  1788. public static void readPreferenceFile() throws FileNotFoundException {
  1789.  
  1790. Alert confirm =
  1791. new Alert(AlertType.CONFIRMATION,
  1792. "Are you sure you do that?!!!");
  1793.  
  1794. Optional<ButtonType> response = confirm.showAndWait();
  1795.  
  1796. if(response.isPresent() && response.get() == ButtonType.CANCEL) {
  1797. System.out.println("You cancelled.");
  1798. System.out.println("\nRedirecting you to preferences menu\n");
  1799. firstTime = false;
  1800. }
  1801. else {
  1802. //CALL FILE TO GRAB FROM
  1803. File myFile = new File("Preferences.txt");
  1804. Scanner inputReaders = new Scanner(myFile);
  1805.  
  1806. //INPUTS PREFERENCES
  1807. String goalsSortDescendingStr = inputReaders.nextLine();
  1808. String namesOrderAscendingStr = inputReaders.nextLine();
  1809. String showSummaryStr = inputReaders.nextLine();
  1810.  
  1811. //APPLYS PREFERENCES VALUES
  1812. if(goalsSortDescendingStr.equals("true")) {
  1813. goalsSortDescending = true;
  1814. goalsSortStatus = "Descending";
  1815. } else {
  1816. goalsSortDescending = false;
  1817. goalsSortStatus = "Ascending";
  1818. }
  1819.  
  1820. if(namesOrderAscendingStr.equals("true")) {
  1821. namesOrderAscending = true;
  1822. namesSortStatus = "Ascending";
  1823. } else {
  1824. namesOrderAscending = false;
  1825. namesSortStatus = "Descending";
  1826. }
  1827.  
  1828. if (showSummaryStr.equals("true")) {
  1829. showSummary = true;
  1830. } else {
  1831. showSummary = false;
  1832. }
  1833.  
  1834. //CALLS FIRST TIME RUNNING PROGRAM TO FALSE
  1835. firstTime = false;
  1836. System.out.print("Now you've done it!!!");
  1837. }
  1838.  
  1839. }
  1840.  
  1841. public static void createEmptyPreferenceFile() throws FileNotFoundException {
  1842. //CREATES EMPTY PREFERENCE FILE
  1843. PrintWriter outputWriterPreference = new PrintWriter("Preferences.txt");
  1844. }
  1845.  
  1846. public static void appendPreferenceFile() throws IOException {
  1847.  
  1848. //APPENDS PREFERENCE FILES
  1849. FileWriter fwriter = new FileWriter("Preferences.txt");
  1850. PrintWriter outputWriterPreference = new PrintWriter(fwriter);
  1851.  
  1852. outputWriterPreference.println(goalsSortDescending);
  1853. outputWriterPreference.println(namesOrderAscending);
  1854. outputWriterPreference.println(showSummary);
  1855.  
  1856. outputWriterPreference.close();
  1857. }
  1858.  
  1859. public static void connectToOtherUser() {
  1860.  
  1861. String selectedUser = (ConnectListView.getSelectionModel().getSelectedItem() == null) ? "C#" : ConnectListView.getSelectionModel().getSelectedItem();
  1862.  
  1863. for(int u = 0; u < connectedVIPS.size(); u++){
  1864. if(selectedUser.equals(connectedVIPS.get(u).getName())){
  1865. textArea.setText("You are already connected to this VIP User");
  1866. u = connectedVIPS.size();
  1867. connect = false;
  1868. }
  1869.  
  1870. }
  1871.  
  1872. if(connect == true) {
  1873. //textArea.setText(playerListVIP.get(ConnectListView.getItems().indexOf(selectedUser)).getName());
  1874. connectedVIPS.add(playerListVIP.get(ConnectListView.getItems().indexOf(selectedUser)));
  1875. }
  1876.  
  1877. textArea.setText("");
  1878. connect = true;
  1879. updateStage.close();
  1880. }
  1881.  
  1882. public static void disconnectFromOtherUser() {
  1883.  
  1884. String selectedUser = (ConnectListView.getSelectionModel().getSelectedItem() == null) ? "C#" : ConnectListView.getSelectionModel().getSelectedItem();
  1885. connectedVIPS.remove((ConnectListView.getItems().indexOf(selectedUser)));
  1886. updateStage.close();
  1887. }
  1888.  
  1889. public static void createEmptyConnectedUsersFile() throws FileNotFoundException {
  1890. //CREATES EMPTY PREFERENCE FILE
  1891. PrintWriter outputWriterPreference = new PrintWriter("ConnectedUsers.txt");
  1892. }
  1893.  
  1894. public static void appendConnectedUsersFile() throws IOException {
  1895.  
  1896. //APPENDS PREFERENCE FILES
  1897. FileWriter fwriter = new FileWriter("ConnectedUsers.txt");
  1898. PrintWriter outputWriterPreference = new PrintWriter(fwriter);
  1899.  
  1900. for(int o = 0; o < connectedVIPS.size(); o++) {
  1901. outputWriterPreference.println(connectedVIPS.get(o).getUserID());
  1902. }
  1903.  
  1904. outputWriterPreference.close();
  1905. }
  1906.  
  1907. public static void readConnectedUsersFile() throws FileNotFoundException {
  1908. //connectedVIPS.clear();
  1909. File myFile = new File("ConnectedUsers.txt");
  1910. Scanner inputReaders = new Scanner(myFile);
  1911.  
  1912. while(inputReaders.hasNextLine())
  1913. connectedVIPS.add(playerListVIP.get((Integer.parseInt(inputReaders.nextLine()) - 1)));
  1914.  
  1915.  
  1916. inputReaders.close();
  1917. }
  1918.  
  1919. }
Add Comment
Please, Sign In to add comment