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.
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?)
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.
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.
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?
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]
That thread is to be found here.
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.
I shall edit this thread to remove discussion about multiple posts; that will remain unchanged in Ranch Office.