I currently have a GUI that keeps a running string that I would like to return when the GUI is exited. I create a cla开发者_Go百科ss of the GUI in a "runner" class and I would then like to use the string. Is there anyway to return this string out of my GUI?
public class Gui {
//running string is edited by an action listener of the gui.
String runningString = "";
...
}
OTHER CLASS FILE
class Runner {
JFrame thisGui = new GUI;
//user uses GUI
thisstring = runningString; // (How do i get running String?)
...
}
Basically, Java classes will not be destroyed unless it is a inter processes. You make your
java.lang.String
havepublic
,static
scope to access from that GUI class.Or else, you can have a
set()
method to write a string in different class before or on exiting out of the GUI, unless the application crashes.
For example:
myframe.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(WindowEvent winEvt) {
updateZonas();
//db.close();
//System.exit(0);
}
});
精彩评论