• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Maneesh Godbole
Saloon Keeper
Posts: 11064
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In future, while posting code, please UseCodeTags

You can store the input as
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and add a action listener to read the text...
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49367
62
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic