Hello, I am having a problem with my application. I have designed a class - DisplayClientRequest which has a constructor and some setters and getter. Apart from this i built very simple JavaFX GUI application. For instance if I create a method in my DisplayClientRequest with paramteres, how would I pass these parameters to labels ? For example if I pass name and surname in my method I would like the name and surname to appear in the label. Is it possible to achieve ?

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package busypointltd;

import java.util.Date;

/**
 *
 * @author Bartosz
 */
public class DisplayClientRequest {






    private String name, surname;    
    private Date date;
    private String[] advertisementType, marketingType;    
    private short marketingDuration;

    //Constructor
    public DisplayClientRequest(String name, String surname){
       this.name = name;
       this.surname = surname;
    }   



    public static DisplayClientRequest getClientRequest(String name, String surname){

        DisplayClientRequest b = setClientRequest(name, surname);
        System.out.println(name + " " + surname);

        return b;
    }


    private static DisplayClientRequest setClientRequest(String name, String surname){
        DisplayClientRequest details = new DisplayClientRequest(name, surname);
        return details;
    }




     public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }


}

and GUI

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package busypointltd;

/**
 *
 * @author Bartosz
 */

import java.awt.Rectangle;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle;
import javafx.stage.Modality;

public class DisplayRequestGUI {




    public static void displayRequest(){

        Stage window = new Stage();
        window.initModality(Modality.APPLICATION_MODAL);
        BorderPane pane = new BorderPane();
        HBox buttons = new HBox();        
        Button btnContinue = new Button("Continue");
        btnContinue.setStyle(" -fx-base: #b6e7c9;");
        Button btnCancel = new Button("Cancel");
        btnCancel.setStyle(" -fx-base: #FF1919;");
        buttons.getChildren().addAll(btnContinue, btnCancel);
        buttons.setAlignment(Pos.CENTER);       
        buttons.setPadding(new Insets(10, 10, 10, 10));
        buttons.setSpacing(10.0);
        pane.setBottom(buttons);

        VBox labels = new VBox();
        Label name = new Label();
        name.setText("a");

        labels.getChildren().addAll(name);      
        pane.setCenter(labels);


        Scene scene = new Scene(pane, 800, 600);
        window.setScene(scene);
        window.setTitle("s");   

        window.showAndWait();
    }


}

Of course I have the main class to launch displayRequest()

Thank you in advance

Hmm... If I understood correctly, you simply add the string when you initilize your Label variable. For example, you passed in first and surname as public static void displayRequest(String firstname, String surname) {, then you would do Label name = new Label(firstname+" "+surname);. Is that what you are asking for?

not exactly, the thing is I have a class called DisplayClientRequest and inside I have a constructor passing some data for example name and surname.

In GUI class I would like to access DisplayClientRequest and pass the parameters to lables.

Thank you for respond

You are having problems because you are using an OO language as if it was purely procedural. The big clues are all those static members and classes whose names are verbs not nouns.

If you make a ClientRequest class to encapsulate a client request, and RequestGUI class to encapsulate an instance of a request UI, then you can pass your instance of ClientReuest to RequestGUI's constructor and use that to access the ClientRequest's getter methods.

sorry I don't really understand what you mean by that (i am new to programming).

Thank you for your help!

I don't have alot of time at the moment, so here's a short version.

The only thing that should be static in this app is your main method

You just need one ClientRequest class, with name, date etc as its instance variables. Give it a constructor that takes name etc as parameters to initialise the variables.
Your display method should just be a method in this class that prints the instance variables
You get and set client request methods are not needed. You can just call ClientRequest's constructor to get a new instance.

Your GUI class should be called RequestGUI, and all the code you have now should be in its constructor. Also the constructor should take an instace of ClientRequest as a parameter so you can access the request's values, eg

public RequestGUI(ClientRequest request) {
    Stage window = etc etc
    ...
    Label name = new Label();
    name.setText(request.getName());
    ...
 }

Now you main should look something like

// (get a name and surname somehow)
ClientRequest request = new ClientRequest(name, surname); // create  request
new RequestGUI(request);  // display request

thank you a lot for your response this is what i really needed. helped a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.