• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Saving and opening an application ?

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello my question is about saving and opening files.
I am creating a user interface application (not an applet ) using Java Swing. My GUI allows teh user to add various buttons to the JPanel and also move the buttons around. The user can also conenct lines to the Buttons and still move the buttons around while the line changes to suit.
I would like to know how does one save a particular configuration heor she has made on teh screen so later he or she can back and open the file and continue.
I know how to make the Open and Save boxes appear.. but they are just for show.. they do nothing. How does one create there own extensions for there own program. For example microsoft word uses .doc . Suppose you want your extension to be .zzz how do you do this.
Ok thanks for reading.. I know you all are busy but any help would be apreciated.. thanks a million... yours respectfully Avin Sinanan
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can name the files anything you want. For saving objects (not text, that is done differently but the same basics apply), just use a FileOutputStream and put it in an ObjectOutputStream. You can specify the filename and the extension (ie "hello.zzz") like this:
output = new ObjectOutputStream(new FileOutputStream("hello.zzz"));
You can save your object like this:
output.writeObject(myObjectToSave);
(Of course you can write multiple objects to the same file by repeating the above)
After you're done saving, you have to close the file, like this:
output.close();
Remember: everything you want to save, has to be serializable. A lot of standard objects (such as String) are, but when you create your own objects and want to save these, they have to implement Serializable (don't forget to import java.io.*;!)
Opening and reading from files is done the same way:
input = new ObjectInputStream(new FileInputStream("hello.zzz"));
MyObject myObject = (MyObject) input.readObject(); (don't forget to typecast here)
input.close();

good luck.
[ February 17, 2002: Message edited by: Allard van Hooff ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Avin
I can't remember the name of the vocab right now but there is an xml standard for defining screen layouts. I ran into it a year or so ago but I'm afraid that you'll have to try a search engine to find it ;->
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic