• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Opening & Saving Problem

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JFrame with 2 buttons namely button1 & button2. The primary role of button1 & button2 is to open-up a dailog to open & save documents.
1.) button1 should open the file and append it to my JTextArea.
2.) button2 should save everything on my JTextArea.
Before they can do this, I need to pass my 2 methods which are openFile() and openSave() to my button1 & button2 Action Listner.
My problem is that I cant seem to open and save files on my JTextArea. Can anyone pls, look if I forgot something or there is an error. If you may can you tweak my codes so that I can do opening & saving on my documents.
Thank you . . .
Here's the process >>>
button1.ActionListner {
openFile();
}
button2.ActionListner {
openSave();
}
Here's my codes :
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I can make out from the code you placed in your post you don't actually do anything with the InputStream and OutputStreams which you create. This means that although you get a handle on the data you want you don't actually access it in any useful sense.
What you need to do is to tell your InputStream "input" to read in wahtever data is contained within the file and then place that data into your JTextArea.
The opposite goes for your save dialog, you need to output the data contained within your JTextArea and write it to the file, the details of which has already been returned by your JFileChooser object. Although I can't actually see a FileOutputStream created anywhere with which to save the file to disk.
For your "Open" button (Assuming the data is saved as a JTextArea object):

Now for your "Save" button:

I'm possibly missing something with only having a small code sample, it would be much better if I could have a copy of the whole class.
Hope this helps!
Andy.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic