my dog learned polymorphism*
The moose likes Java in General and the fly likes deal with text on window closing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "deal with text on window closing" Watch "deal with text on window closing" New topic
Author

deal with text on window closing

Bryce V.
Greenhorn

Joined: Nov 16, 2003
Posts: 13
When I have a window close, i have this code( this is from a class that extends JDialog, just in case you want to know):

Within the same function i have a JTextField & a String. What i would like to have happen is as the window closes, put the JTextField info(getText()) to the string or just do a straight return.
Is this possible?
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Actually u can do that if u want to use that String value in other places. But I'm wondering why do u want to get the value in the windowClosing method. I mean I'm not clear with your goal...
It's better, if u provide information about your program... :roll:


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Bryce V.
Greenhorn

Joined: Nov 16, 2003
Posts: 13
Please forgive my desire to have an air of mystery about my program. Let me just say that i'm creating a Swing GUI frontend for a command line utility.Its nothing really all that special to have this mystery... but i'm not ready to release the program and code just yet... hope to have a beta ready by the end of the year( hope?!?!)
the code for the function in particular is as follows( kinda long):

I didn't know where else to put the code,that i was asking about in the original post, but i don't know where i will be able to put the code to return a String from the JTextField.
Sharing and showing me how to do this properly would be great.
--PS i use to be a CCNA too... but after i passed my test, the dot bomb hit and i never got to get expirence using my ccna(paid for the training myself). 3 years later, it expired, and i still don't have a job with routers or a tech job in general
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
I think u r calling the method that u mentioned above from the constructor method of the class, aren't u? Because it looks like ur method is for the component initialization...
Well, for the textfield, u can put the code that fetch the string from that textfield in the actionPerformed method of the ActionListener interface that your class implements... I can say that ur button should add that listener to take care of the actions that u will make on that button...
So just use ur string fetching code in the actionPerformed method... Hope it helps u....
Bryce V.
Greenhorn

Joined: Nov 16, 2003
Posts: 13
Thanks again for your advice, but when i try to do what you ask recommend:

i get this error:

SO now if i set the variable as final, i can't change it( or add the getText() to it). What simple mistake am i making??
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
No..no..no... Just simply make ur class implement ActionListener and
Use like this...

And put the body of the method outside like this... Don't forget to declare the user_set_path and jTextField1 somewhere as instance variables...

Hope it helps.....
Bryce V.
Greenhorn

Joined: Nov 16, 2003
Posts: 13
I'll bite... this is the whole class that i'm creating. I guess i have a lot to learn about how to create GUI applications. I was hoping this would be a simple "addition" to my class... but it seems like i might need to do a complete restucturing. Sorry if its unformatted.

How would you change things around to get the functionality i'm trying for?
Bryce V.
Greenhorn

Joined: Nov 16, 2003
Posts: 13
Sorry, but the "implements ActionListener" was added after reading your post. It was adding it and thinking about it that i don't think it will work with my current design. So please disregard that part of my code.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Here is the compilable code... One thing is that I'm not sure where u created the class named "gpg_interact", which u used in the Gpg_About() as local variable and Set_Gpg_Path() mehod as method parameter... I hope u can continue ur coding... I'm not supposed to give u the complete program because it will make u less improvement to ur coding skill.... Hope u understand the situation...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: deal with text on window closing
 
Similar Threads
JOptionPane.showInputDialog to accept multiple inputs
How to stop JTextField collapsing when using GridBagLayout?
how to create an Array of JTextField !!!!
public vs. private modifier
Lining up JTextFields next to JLabels