File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Writing to a File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing to a File" Watch "Writing to a File" New topic
Author

Writing to a File

Holly Leery
Ranch Hand

Joined: Sep 08, 2004
Posts: 97
Hello there! I posted this code a few days ago, but I really shouldn�t have at the time because it was not near complete. But, I have made a lot changes and added a few things to the application. So now basically I am just wondering if someone could just let me know if I am on the right track with the switch statement and the action listeners.

The application I am building will calculate the total sales for any number of salesmen. The application will allow the salesman to enter their name, the product (numbered 1-5) they sold as well as the amount of products they sold. They would then hit done to tell the application that the salesman is done entering his information. Once all of the salesmen have entered their information they can hit Grand Total and the grand total of those sales will display in the text area.

TOTAL SALES

NameXXXXXX
NameXXXXXX

TotalXXXXXX

I put together a GUI in flow layout, but the text fields are not allowing me to type in the field, is there a particular reason that might happen? Maybe I just missed something.

Also, the final information will be printed in alphabetical order, which I haven't done yet, but I think I will use sort to do that. This will all be sent to a .txt file as well by the way.

So anyway that is a brief run down of what I am trying to do. Any little tip just letting me know I am on the right track or whatever would be appreciated!! Thanks so much everyone!!



Class Salesman:
Holly Leery
Ranch Hand

Joined: Sep 08, 2004
Posts: 97
Ok I have even bigger changes than before. I am sorry I keep posting this, I am just hoping to get a little feedback on how I am doing. Everything seems to be working great (it compiles) except for when it should be reading and writing the data to the textarea and to the .txt file. I'm wondering if the problem might have to do with myList. Could this be the case?



Matti Poro
Ranch Hand

Joined: Dec 03, 2005
Posts: 41
You should open a file stream only if you need to and close it right after you don't need it anymore. From Sun's tutorial: "A program should close a stream as soon as it is done with it, in order to free up system resources." Also your members are static which isn't necessary.
Holly Leery
Ranch Hand

Joined: Sep 08, 2004
Posts: 97
Are you saying I might need to move the file writer and buffer to open just before I run the calculations and close after I print the information to the output? Everything seems to be running properly but the output is not being sent to the text area and the calculations are not taking place. The text is being sent to the .txt file. The calculations just are not happening.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing to a File
 
Similar Threads
Using JOptionPane in NoSalesException
Reading Objects and Formatting Ouput
Reading and Writing Objects
Switch Statement and GUI
Creating Objects without the "New" Keyword