aspose file tools*
The moose likes Beginning Java and the fly likes I  would like save the user inputs form JTextField ab,l m,n,o etc. how can I do this please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I  would like save the user inputs form JTextField ab,l m,n,o etc. how can I do this please help" Watch "I  would like save the user inputs form JTextField ab,l m,n,o etc. how can I do this please help" New topic
Author

I would like save the user inputs form JTextField ab,l m,n,o etc. how can I do this please help

Lee Seol
Greenhorn

Joined: Jun 27, 2011
Posts: 3
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10378
    
    8

In future, while posting code, please UseCodeTags

You can store the input as


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
... and add a action listener to read the text...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38879
    
  23
Maneesh Godbole wrote:In future, while posting code, please UseCodeTags . . .
. . . and also go through some style guidelines. I don't agree with everything there, nor in the Sun style guide referenced there, but things like consistent indentation and use of whitespace would make your code much easier to read.
So many people are taught to use \n, but here you find you ought to use %n rather than \n. You should use printf rather than println to get %n to work.
So many people are taught to use addActionListener(this), but that is by no means object-oriented programming. You should create classes which implement the ActionListener interface, rather than have a display Component implement that interface. Even though many books, and the Java tutorials use that comstruct, I believe you should never use it.
It is worth checking what sort of Listener can be added to a text component. You can find Bruce Eckel's Thinking in Java which has an example program in which displays all the addXXXListener methods a particular class has. Or you can go to the API documentation and count them by hand. there may be scores of them. Remember to look in the blocks headed "methods inherited from XYZ". You will find an ActionListener is likely to be fired whenever you use the enter key inside your text field. You can find other Listeners which are fired whenever you alter add or remove text from it. Consider which is most appropriate to your requirements.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Campbell Ritchie wrote:So many people are taught to use addActionListener(this), but that is by no means object-oriented programming.

Thanks for the information...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38879
    
  23
. . . at least I don't think it's object-oriented. You end up with a block of if-elses. The worst I ever saw was from somebody on the Ranch a few years ago, who was trying to make a calculator, and ended up with an actionPerformed method with this sort of if blocks:. . . or something like that. A whole screenful. And you could have reduced it to a simple for loop with the right class.She seemed to be having so many problems with the rest of her code, I didn't have the heart to tell her to chuck ¾ of that class in the recycle bin.
 
jQuery in Action, 2nd edition
 
subject: I would like save the user inputs form JTextField ab,l m,n,o etc. how can I do this please help