src/com/company/Client/AddCloseContact.java
@Override
    public void start(Stage primaryStage) {

        this.addCloseContactWindow = primaryStage;

        // Method responsible for saving user information, when the user interface window is closed
        this.addCloseContactWindow.setOnCloseRequest(e -> {
            e.consume();

            try {
                out = new PrintWriter(socket.getOutputStream(), true);

                this.client.setCommand("LOGOUT");
                out.println(this.client.toString());

                addCloseContactWindow.close();
                System.exit(-1);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        });

        File file = new File("src/com/company/Data/Users.json");

        JSONParser jsonParser = new JSONParser();

        try {
            JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(file.getPath()));

            JSONArray listCounty = (JSONArray) obj.get("Registry");

            this.listUserId = new ArrayList<>();
            JSONObject county;
            String idPerson;

            for (int i = 0; i < listCounty.size(); i++) {
                county = (JSONObject) listCounty.get(i);

                if (!(((Long) county.get("id")).intValue() == (this.client.getId()))) {
                    idPerson = county.get("id").toString();
                    listUserId.add(idPerson);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }

        // Scene Title
        this.sceneLabel = new Label();
        this.sceneLabel.setText("NEARBY CONTACTS");
        this.sceneLabel.setFont(new Font(30));

        // Description
        this.titleLabel = new Label();
        this.titleLabel.setText("If you were in contact with someone, add the person Health User no. here:");
        this.titleLabel.setFont(new Font(20));

        // Summary
        this.descLabel = new Label();
        this.descLabel.setText("If you want to add multiple contacts, separate the it by \";\".");
        this.descLabel.setFont(new Font(17));

        // Button add contact
        this.addContactButton = new Button("Add");

        // Input Contact ID
        this.idContactInput = new TextField();
        this.addContactButton.setOnAction(e -> {
            try {
                if (this.idContactInput.getText() != "") {

                    this.client.setCommand("ADD CONTACTS");
                    this.client.setListContact(this.client.getId() + ";" + this.idContactInput.getText());

                    this.out = new PrintWriter(socket.getOutputStream(), true);
                    this.out.println(this.client.toString());

                } else {
                    AlertUserBox.display("Nearby Contacts", "Add a contact first!");
                }
            } catch (UnknownHostException ex) {
                System.out.println("Unknown Host.");
                System.exit(1);
            } catch (IOException ex) {
                System.out.println(ex.getMessage());
            }
        });

        this.contact = new Label();
        this.contact.setText("Contacts: ");

        // ComboBox of the registered users
        this.comboBox = new ComboBox<>();
        this.comboBox.setValue("Identify the users");
        this.comboBox.getItems().addAll(listUserId);

        // Click actions on comboBox
        this.comboBox.setOnAction(e -> {
            // System.out.println("User selected: " + comboBox.getValue());

            // System.out.println(this.comboBox.getSelectionModel().getSelectedItem());

            String idPerson = String.valueOf(this.comboBox.getSelectionModel().getSelectedItem());

            String content = this.idContactInput.getText();

            if (content.equals(""))
                content += idPerson;
            else {
                if (!content.contains(idPerson))
                    content += ";" + idPerson;
            }

            this.idContactInput.setText(content);
        });

        // Button "Return to Main Menu"
        this.returnMenuButton = new Button("Return to Main Menu");
        this.returnMenuButton.setOnAction(e -> {
            MenuPage menuPage = null;

            try {
                menuPage = new MenuPage(socket, this.client);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }

            try {
                menuPage.start(addCloseContactWindow);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        });

        VBox titlesContainer = new VBox(10);
        titlesContainer.setAlignment(Pos.CENTER);
        titlesContainer.getChildren().addAll(this.sceneLabel, this.titleLabel, this.descLabel);

        HBox inputContainer = new HBox(10);
        inputContainer.setAlignment(Pos.CENTER);
        inputContainer.setPadding(new Insets(0, 40, 40, 40));
        inputContainer.getChildren().addAll(this.contact, this.comboBox, this.idContactInput);

        VBox contentContainer = new VBox(10);
        contentContainer.setAlignment(Pos.CENTER);
        contentContainer.getChildren().addAll(inputContainer, this.addContactButton, this.returnMenuButton);

        BorderPane borderPanelayout = new BorderPane();
        borderPanelayout.setCenter(contentContainer);
        borderPanelayout.setTop(titlesContainer);

        this.addCloseContactScene = new Scene(borderPanelayout, LoginMenu.getSceneWidth(), LoginMenu.getSceneHeight());

        this.addCloseContactWindow.setScene(this.addCloseContactScene);
        this.addCloseContactWindow.show();
    }
/**
     * Method responsible for starting the user interface "Add contacts"
     *
     * @param primaryStage - Main Container of JavaFX
     */
Method responsible for starting the user interface "Add contacts"
@param primaryStage - Main Container of JavaFX
Method responsible for starting the user interface " Add contacts " @param primaryStage - Main Container of JavaFX
@Override
    public void start(Stage primaryStage) {
        this.addCloseContactWindow = primaryStage;
        this.addCloseContactWindow.setOnCloseRequest(e -> {
            e.consume();
            try {
                out = new PrintWriter(socket.getOutputStream(), true);
                this.client.setCommand("LOGOUT");
                out.println(this.client.toString());
                addCloseContactWindow.close();
                System.exit(-1);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        });
        File file = new File("src/com/company/Data/Users.json");
        JSONParser jsonParser = new JSONParser();
        try {
            JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(file.getPath()));
            JSONArray listCounty = (JSONArray) obj.get("Registry");
            this.listUserId = new ArrayList<>();
            JSONObject county;
            String idPerson;
            for (int i = 0; i < listCounty.size(); i++) {
                county = (JSONObject) listCounty.get(i);
                if (!(((Long) county.get("id")).intValue() == (this.client.getId()))) {
                    idPerson = county.get("id").toString();
                    listUserId.add(idPerson);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        this.sceneLabel = new Label();
        this.sceneLabel.setText("NEARBY CONTACTS");
        this.sceneLabel.setFont(new Font(30));
        this.titleLabel = new Label();
        this.titleLabel.setText("If you were in contact with someone, add the person Health User no. here:");
        this.titleLabel.setFont(new Font(20));
        this.descLabel = new Label();
        this.descLabel.setText("If you want to add multiple contacts, separate the it by \";\".");
        this.descLabel.setFont(new Font(17));
        this.addContactButton = new Button("Add");
        this.idContactInput = new TextField();
        this.addContactButton.setOnAction(e -> {
            try {
                if (this.idContactInput.getText() != "") {
                    this.client.setCommand("ADD CONTACTS");
                    this.client.setListContact(this.client.getId() + ";" + this.idContactInput.getText());
                    this.out = new PrintWriter(socket.getOutputStream(), true);
                    this.out.println(this.client.toString());
                } else {
                    AlertUserBox.display("Nearby Contacts", "Add a contact first!");
                }
            } catch (UnknownHostException ex) {
                System.out.println("Unknown Host.");
                System.exit(1);
            } catch (IOException ex) {
                System.out.println(ex.getMessage());
            }
        });
        this.contact = new Label();
        this.contact.setText("Contacts: ");
        this.comboBox = new ComboBox<>();
        this.comboBox.setValue("Identify the users");
        this.comboBox.getItems().addAll(listUserId);
        this.comboBox.setOnAction(e -> {
            String idPerson = String.valueOf(this.comboBox.getSelectionModel().getSelectedItem());
            String content = this.idContactInput.getText();
            if (content.equals(""))
                content += idPerson;
            else {
                if (!content.contains(idPerson))
                    content += ";" + idPerson;
            }
            this.idContactInput.setText(content);
        });
        this.returnMenuButton = new Button("Return to Main Menu");
        this.returnMenuButton.setOnAction(e -> {
            MenuPage menuPage = null;
            try {
                menuPage = new MenuPage(socket, this.client);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
            try {
                menuPage.start(addCloseContactWindow);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        });
        VBox titlesContainer = new VBox(10);
        titlesContainer.setAlignment(Pos.CENTER);
        titlesContainer.getChildren().addAll(this.sceneLabel, this.titleLabel, this.descLabel);
        HBox inputContainer = new HBox(10);
        inputContainer.setAlignment(Pos.CENTER);
        inputContainer.setPadding(new Insets(0, 40, 40, 40));
        inputContainer.getChildren().addAll(this.contact, this.comboBox, this.idContactInput);
        VBox contentContainer = new VBox(10);
        contentContainer.setAlignment(Pos.CENTER);
        contentContainer.getChildren().addAll(inputContainer, this.addContactButton, this.returnMenuButton);
        BorderPane borderPanelayout = new BorderPane();
        borderPanelayout.setCenter(contentContainer);
        borderPanelayout.setTop(titlesContainer);
        this.addCloseContactScene = new Scene(borderPanelayout, LoginMenu.getSceneWidth(), LoginMenu.getSceneHeight());
        this.addCloseContactWindow.setScene(this.addCloseContactScene);
        this.addCloseContactWindow.show();
    }
@ Override public void start ( Stage primaryStage ) { this . addCloseContactWindow = primaryStage ; this . addCloseContactWindow . setOnCloseRequest ( e -> { e . consume ( ) ; try { out = new PrintWriter ( socket . getOutputStream ( ) , true ) ; this . client . setCommand ( "LOGOUT" ) ; out . println ( this . client . toString ( ) ) ; addCloseContactWindow . close ( ) ; System . exit ( - 1 ) ; } catch ( IOException ioException ) { ioException . printStackTrace ( ) ; } } ) ; File file = new File ( "src/com/company/Data/Users.json" ) ; JSONParser jsonParser = new JSONParser ( ) ; try { JSONObject obj = ( JSONObject ) jsonParser . parse ( new FileReader ( file . getPath ( ) ) ) ; JSONArray listCounty = ( JSONArray ) obj . get ( "Registry" ) ; this . listUserId = new ArrayList < > ( ) ; JSONObject county ; String idPerson ; for ( int i = 0 ; i < listCounty . size ( ) ; i ++ ) { county = ( JSONObject ) listCounty . get ( i ) ; if ( ! ( ( ( Long ) county . get ( "id" ) ) . intValue ( ) == ( this . client . getId ( ) ) ) ) { idPerson = county . get ( "id" ) . toString ( ) ; listUserId . add ( idPerson ) ; } } } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( ParseException e ) { e . printStackTrace ( ) ; } this . sceneLabel = new Label ( ) ; this . sceneLabel . setText ( "NEARBY CONTACTS" ) ; this . sceneLabel . setFont ( new Font ( 30 ) ) ; this . titleLabel = new Label ( ) ; this . titleLabel . setText ( "If you were in contact with someone, add the person Health User no. here:" ) ; this . titleLabel . setFont ( new Font ( 20 ) ) ; this . descLabel = new Label ( ) ; this . descLabel . setText ( "If you want to add multiple contacts, separate the it by \";\"." ) ; this . descLabel . setFont ( new Font ( 17 ) ) ; this . addContactButton = new Button ( "Add" ) ; this . idContactInput = new TextField ( ) ; this . addContactButton . setOnAction ( e -> { try { if ( this . idContactInput . getText ( ) != "" ) { this . client . setCommand ( "ADD CONTACTS" ) ; this . client . setListContact ( this . client . getId ( ) + ";" + this . idContactInput . getText ( ) ) ; this . out = new PrintWriter ( socket . getOutputStream ( ) , true ) ; this . out . println ( this . client . toString ( ) ) ; } else { AlertUserBox . display ( "Nearby Contacts" , "Add a contact first!" ) ; } } catch ( UnknownHostException ex ) { System . out . println ( "Unknown Host." ) ; System . exit ( 1 ) ; } catch ( IOException ex ) { System . out . println ( ex . getMessage ( ) ) ; } } ) ; this . contact = new Label ( ) ; this . contact . setText ( "Contacts: " ) ; this . comboBox = new ComboBox < > ( ) ; this . comboBox . setValue ( "Identify the users" ) ; this . comboBox . getItems ( ) . addAll ( listUserId ) ; this . comboBox . setOnAction ( e -> { String idPerson = String . valueOf ( this . comboBox . getSelectionModel ( ) . getSelectedItem ( ) ) ; String content = this . idContactInput . getText ( ) ; if ( content . equals ( "" ) ) content += idPerson ; else { if ( ! content . contains ( idPerson ) ) content += ";" + idPerson ; } this . idContactInput . setText ( content ) ; } ) ; this . returnMenuButton = new Button ( "Return to Main Menu" ) ; this . returnMenuButton . setOnAction ( e -> { MenuPage menuPage = null ; try { menuPage = new MenuPage ( socket , this . client ) ; } catch ( IOException ioException ) { ioException . printStackTrace ( ) ; } try { menuPage . start ( addCloseContactWindow ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } } ) ; VBox titlesContainer = new VBox ( 10 ) ; titlesContainer . setAlignment ( Pos . CENTER ) ; titlesContainer . getChildren ( ) . addAll ( this . sceneLabel , this . titleLabel , this . descLabel ) ; HBox inputContainer = new HBox ( 10 ) ; inputContainer . setAlignment ( Pos . CENTER ) ; inputContainer . setPadding ( new Insets ( 0 , 40 , 40 , 40 ) ) ; inputContainer . getChildren ( ) . addAll ( this . contact , this . comboBox , this . idContactInput ) ; VBox contentContainer = new VBox ( 10 ) ; contentContainer . setAlignment ( Pos . CENTER ) ; contentContainer . getChildren ( ) . addAll ( inputContainer , this . addContactButton , this . returnMenuButton ) ; BorderPane borderPanelayout = new BorderPane ( ) ; borderPanelayout . setCenter ( contentContainer ) ; borderPanelayout . setTop ( titlesContainer ) ; this . addCloseContactScene = new Scene ( borderPanelayout , LoginMenu . getSceneWidth ( ) , LoginMenu . getSceneHeight ( ) ) ; this . addCloseContactWindow . setScene ( this . addCloseContactScene ) ; this . addCloseContactWindow . show ( ) ; }
Method responsible for starting the user interface "Add contacts"
 @param primaryStage - Main Container of JavaFX
Method responsible for starting the user interface " Add contacts " @param primaryStage - Main Container of JavaFX
// Method responsible for saving user information, when the user interface window is closed // Scene Title // Description // Summary // Button add contact // Input Contact ID // ComboBox of the registered users // Click actions on comboBox // System.out.println("User selected: " + comboBox.getValue()); // System.out.println(this.comboBox.getSelectionModel().getSelectedItem()); // Button "Return to Main Menu"