This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help on reading textfield on 1 class from another class and using it to create a file

 
henry kay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

i wish to read the text input by user on 1 class and use that textfield input in another class to create a file.

but currently , when i just click the menu item, it auto create the file out with the default text in the textfield.

i attached my code in below, tried to attached the file but unable to attach.
the one in bold are the 2 classes i trying to get the thing to work.

Any help is greatly appreciated.



EDIT my mw: Added code tags.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

I edited your post to use Code Tags. Unfortunately, your post didn't have indentation, so that wasn't preserved, but at least you have line numbers now. I didn't see any bold, so perhaps you can direct us to specific lines...?

(Posting code is helpful, but you're more likely to get useful responses if you keep your post brief and to the point. Perhaps there's some way to reduce your question to a general case?)
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
marc weber wrote:(Posting code is helpful, but you're more likely to get useful responses if you keep your post brief and to the point. Perhaps there's some way to reduce your question to a general case?)

Right. We prefer an SSCCE instead of almost 700 lines of code. To be honest, the length of code combined with the lack of indentation made me skip over it completely.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[See Ranch Office thread]
 
henry kay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
marc, thanks for the aid to put it into a code tag whatever it means.

basically this is my assignment from my school which requires me to create an application for a student registration program.
i dun really know much of java swing programming so i put the code together using youtube, google and other source as my research source.

to be brief, the desire result is that i had a menu bar with menu item. when i click on the enroll new student menu item, it suppose to go to a pop up window which in this case i use a new frame . on the new window, there are some textfield that allow user to input data and then when i click submit, i wish to use the input from user to create a text file and then store the other textfield input in the text file.

what i facing now is that when i click on the menu item enroll new student, it create a text file with the text that i put as the default text without i clicking the submit button.


rob, what does SSCCE mean?


michael , i did post on multiple forum to get the maximum reply to my problem. how sure are you that it is not my code? if its not my code, why would i post code that is not working to get it working? it fine if you do not wish to help , but please to do not generalize people posting on multi forum asking for help. although i thank you for your input even though it is useless.
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's pretty awful code. Maybe you should consider reading a good book on java swing programming, or at least some of the useful tutorials out there:
http://java.sun.com/docs/books/tutorial/uiswing/
http://faq.javaranch.com/java/SwingFaq

There're several 'problems' in your code. The specific one you're asking for is located in your ActionListener implementation 'submitNewEnroll' (you should consider following the Naming Conventions).

When you instantiate the class and add it as ActionListener for the submit button, the textfield has the default content (preallocated). You create a file on construction time of 'submitNewEnroll' and do nothing on a button click (method actionPerformed() is empty). You should read the content of your textfield in your 'actionPerfomed()' method and also create the file there. That's the whole point of using an ActionListener ... do do something in the actionPerformed() method, don't you think?
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
henry kay wrote:rob, what does SSCCE mean?

Do you see these little dots below SSCCE? That means you can click on it and a new page opens that will explain what it means.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Afraid nobody will go through all that code to try and find the problem. The idea behind a school assignment is that you do the work, and ask for help on specific parts. [See Ranch Office thread]

You will need to read the link which appears against SSCCE ← like that, so you can work out what to post. You would do better to create a small example which reads the student's name from a JOptionPane (input dialog) and writes it to the file. Then you can add to it gradually. You should also not try to compile 700 lines of code all at once; you should run your application every time you add 7 lines of code; then you can see it working in parts.

[See Ranch Office thread]
 
henry kay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[See Ranch Office Thread]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[See Ranch Office thread.]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think at this point, I shall be obliged to transfer this thread; I shall duplicate it to the Ranch Office forum, where discussion about posting in several places should continue, please.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I earlier wrote:I think at this point, I shall be obliged to transfer this thread; I shall duplicate it to the Ranch Office forum, where discussion about posting in several places should continue, please.
That thread is to be found here.

I shall edit this thread to remove discussion about multiple posts; that will remain unchanged in Ranch Office.
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Henry
Any comments on my remarks about your ActionListener? Did you even read it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic