Jump to content

Get an instance of a Scene (javafx)


Qubit

Recommended Posts

Im trying to find a way so that in main i can declare a class that extends stage and call upon it like a jframe object.

 //I want something like this...
Class Gui extends Stage { ...}
 
 
Class Main{
 
public static void main(String[] args){
 Gui myGui =new Gui();
 
 Gui.start();
 
 String textboxField = Gui.getSomeRandomField();
 
 
}
}
 

At the moment im stuck with having all my code jammed into main and it is an eye soar every time I peek at the code

 

 

Goal is to create a controller to be able to interact with the gui class and my model class.

https://github.com/jaavant/ExcelFormatter

Edited by Qubit
Link to comment
Share on other sites

Alright, so based on the stuff you've shown here, the best way of doing this that I can think of for you is using getters / setters in the Main class. The reason for this, is because I believe you shouldn't access the GUI everytime you need data, as its an independent object. However, if this approach doesnt suit you, you can always do a singleton.

 

Getter / Setter design:

public class GUI extends Stage {
    private Main instance;

    public GUI(Main instance){
        this.instance = instance;
    }


    // Can be any event, such as the start button being pressed.
    public void start(){
       instance.setTxtBox1(txtBox1.toString()) // whatever is in textbox 1, i forgot the statement to return that
    }

}

public class Main {
    
    private String txtBox1;

    public static void main(String[] args){
        new GUI(this);
    }


    public String getTxtBox1(){
        return txtBox1;
    }

    public void setTxtBox1(String str){
        txtBox1 = str;
    }
}
Edited by Tom
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...