java - Referring to Jframe from separate class -


so have gui initialize using "this." follows:

public class gui extends jframe {      public static void main(string[] args) {          gui gui = new gui();         gui.setvisible(true);         gui.setextendedstate(jframe.maximized_both);     }     //constructor     public gui() {         this.setpreferredsize(new dimension(1920, 1080));         this.getcontentpane().setbounds(new rectangle(0, 0, 1920, 1080));         this.setbounds(new rectangle(0, 0, 1920, 1080));         this.setbackground(color.white);         this.settitle("gui");         this.setbounds(0, 0, 1919, 1080);         this.setdefaultcloseoperation(jframe.exit_on_close);         this.getcontentpane().setlayout(null);          etc.     } } 

i want use .setcursor method separate class on frame created in gui class.

public class otherclass {     public static void otherclassmethod() {         *something*.setcursor(...);     } } 

is there way refer frame initialized in gui class can use setcursor etc in separate class, or need make methods referring frame in gui class? i'm using setcursor method in separate class organizational reasons, put in main gui class if need be, , use this.setcursor(...) there instead.

also, if trying bad programming practice, apologize, , please give me reason why such, learn this.

as per accepted answer, altered code such:

public class gui extends jframe {      public static gui gui;      public static void main(string[] args) {          gui = new gui();         gui.setvisible(true);         gui.setextendedstate(jframe.maximized_both);     }     //constructor     public gui() {         this.setpreferredsize(new dimension(1920, 1080));         this.getcontentpane().setbounds(new rectangle(0, 0, 1920, 1080));         this.setbounds(new rectangle(0, 0, 1920, 1080));         this.setbackground(color.white);         this.settitle("gui");         this.setbounds(0, 0, 1919, 1080);         this.setdefaultcloseoperation(jframe.exit_on_close);         this.getcontentpane().setlayout(null);          etc.     } } 

i'm going leave original code altered code learning. obviously, issue fixed , i'm little embarrassed didn't think of myself, not apparent me right away. else can learn this.

this basic java:

public class gui extends jframe {      public static gui gui;      public static void main(string[] args) {          gui = new gui();         gui.setvisible(true);         gui.setextendedstate(jframe.maximized_both);     } 

now, put gui.gui.setcursor (etc.)


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -