java - How to use the value from a JFrame in another class -


i using jframe accepts value user , stores in variable (filepath). want use value in class. how can hold value jframe , use in class?

jframe code:

jfilechooser filechooser = new jfilechooser();         filechooser.setdialogtitle("specify file save");          int userselection = filechooser.showsavedialog(this);         if (userselection == jfilechooser.approve_option) {             file filetosave = filechooser.getselectedfile();             string filepath = filetosave.getabsolutepath();         } 

class code:

string filename=""; 

i want filepath value filename string.

any help?

you can create static method in class want hold value. eg.

class {      static string filename;      public static void getvalue(string value) {         filename = value;     } } 

then once file path from.

string filepath = filetosave.getabsolutepath(); 

just after call static method of other class. instance in case class get.

get.getvalue(filepath); 

or crete constructor of class gets string value.

class {          string filename;          get(string value) {             filename = value;         }     } } 

while creating object of class, send value constructor.

get g = new get(filepath); 

and simpler. introduce static variable in holder class, jframe class set value filepath.

class {

    static string filename; 

}

then set value of filename filepath below.

get.filename = filepath; 

Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

android - How to create dynamically Fragment pager adapter -