java - How to name JFrame in a constructor -


question may different expected, i'm creating utility function jframes make easier future me.

public void setjframe(string title, int w,int h, jframe name, boolean maximize){     name.setsize(w, h);     name.settitle(title);      if (maximize == true) {         name.setextendedstate(name.getextendedstate()|jframe.maximized_both);     } else {         name.setlocationrelativeto(null);     } } 

i want ability name jframe type in parameters. @ moment, when type in string spits out error saying can't use string? want "name" string variable can type in string value , have object named that.

edit: need make question more clear...

packagename.setjframe("title of frame", 500, 800, f, false); 

returns error:

exception in thread "main" java.lang.error: unresolved compilation problems:

f cannot resolved

f cannot resolved

at gui.guimain.guiset(guimain.java:17)

at urapackage.main.main(main.java:8)

eclipse says method f not applicable constructor

using method, setjframe, need pass instantiated new jframe forth parameter such:

import java.awt.eventqueue; import javax.swing.jframe;  public class createjframe {      public static void main(string[] args) {         eventqueue.invokelater(new runnable() {             public void run() {                 try {                     jframe frame1 = new jframe();                     setjframe("title of first frame", 500, 800, frame1, false);                     frame1.setvisible(true);                      jframe frame2 = new jframe();                     setjframe("title of second frame", 100, 200, frame2, false);                     frame2.setvisible(true);                      jframe frame3 = new jframe();                     setjframe("title of third frame", 100, 200, frame3, true);                     frame3.setvisible(true);                 } catch (exception e) {                     e.printstacktrace();                 }             }         });     }      public static void setjframe(string title, int w, int h, jframe name, boolean maximize) {         name.setsize(w, h);         name.settitle(title);          if (maximize == true) {             name.setextendedstate(name.getextendedstate() | jframe.maximized_both);         } else {             name.setlocationrelativeto(null);         }     } } 

if want forth parameter string, either extend jframe , specify additional constructor(s) accept string, or can create method whereby jframe object returned.

edit: unless of course, meant naming internal variable name. functionality not possible during runtime. can't imagine use such function anyways. above paragraph assumes mean setting name of jframe (via setname()).


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -