File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes help on reading textfield on 1 class from another class and using it to create a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help on reading textfield on 1 class from another class and using it to create a file" Watch "help on reading textfield on 1 class from another class and using it to create a file" New topic
Author

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

henry kay
Greenhorn

Joined: Jun 15, 2010
Posts: 3
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

Joined: Aug 31, 2004
Posts: 11343

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?)

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
[See Ranch Office thread]
henry kay
Greenhorn

Joined: Jun 15, 2010
Posts: 3
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

Joined: Nov 18, 2006
Posts: 174
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?


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

Joined: Jun 15, 2010
Posts: 3
[See Ranch Office Thread]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
[See Ranch Office thread.]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

Joined: Nov 18, 2006
Posts: 174
@Henry
Any comments on my remarks about your ActionListener? Did you even read it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help on reading textfield on 1 class from another class and using it to create a file
 
Similar Threads
GridBagLayout problem
GridBagLayout:: a few Qs
Java Programming Help (conversions)
GridBagLayout...!
help automate code