Qubit Posted July 20, 2016 Share Posted July 20, 2016 (edited) 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 July 20, 2016 by Qubit Quote Link to comment Share on other sites More sharing options...
Tom Posted July 20, 2016 Share Posted July 20, 2016 (edited) 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 July 20, 2016 by Tom Quote Link to comment Share on other sites More sharing options...