开发者

How Do I return a value out a GUI?

开发者 https://www.devze.com 2023-02-15 12:46 出处:网络
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 s

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?)

    ...
}


  1. Basically, Java classes will not be destroyed unless it is a inter processes. You make your java.lang.String have public, static scope to access from that GUI class.

  2. 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);
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号