• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

deal with text on window closing

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Bryce V.
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
reply
    Bookmark Topic Watch Topic
  • New Topic