2011-07-22 9 views
1

私は100以上のコンポーネントを持つ10以上のクラスを持つクライアントアプリケーションプログラムを持っています。プログラムが実行されると、ユーザーは数値を入力したり、項目を選択したり、チェックボックスを閉じるなどの操作をします。プログラムが閉じられたときにすべてのデータ入力を保存し、プログラムを再度実行する機能が必要です以前の時間からのすべてのデータが実行されます。大量の動的ユーザー入力を保存する

私は直列化を調べましたが、保存する必要があるもののいくつかは直列化できないため動作しませんでした。私はSingleFrameApplicationとセッションストレージについても見てきましたが、無駄でした。

ファイルに書き込むと、面倒なコーディングが必要になり、おそらく効率が悪いでしょう。どのように私は問題のこの毛むくじゃくの獣に取り組むことができるかについてのアイデアは誰にもありますか?

更新:

は@homeは、私は次のようでしたお勧め何を:私はプログラムが空白のJTabbedPaneで実行したときにポップアップするこれらの変更のすべての後

public Main() throws FileNotFoundException {  
    initComponents(); 
    //read the file 
    Read(); 
    //... 
} 

private void formWindowClosing(java.awt.event.WindowEvent evt) { 
    try { 
     //write to the file, the program is closing 
     Write(); 
    } catch (FileNotFoundException ex) { 
     Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
    } 
} 

private void Read() throws FileNotFoundException { 
    try{ 
     XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream("test.xml"))); 
     //set the JTabbedPane to what is in the file 
     tab = (JTabbedPane) decoder.readObject(); 
     decoder.close(); 
    }catch(Exception e){ 
     //there was no test.xml file so create one 
     XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("test.xml"))); 
     encoder.writeObject(null); 
     encoder.close(); 
    } 

} 

private void Write() throws FileNotFoundException { 
    XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("test.xml"))); 
    //clear all previous things in the file 
    encoder.flush(); 
    //write the JTabbedPane into the file 
    encoder.writeObject(tab); 
    encoder.close(); 
} 

。なぜこれが事実であるのか誰も説明できますか?

+0

あの、あなたは脂肪の話をしています(リッチクライアントアプリケーションまたはWebアプリケーション? – home

+0

クライアントアプリケーション –

答えて

0

あなたは、単にXMLのエンコーダとデコーダを見て、JavaBeans仕様と互換性のあるオブジェクトをシリアル化したい場合:http://download.oracle.com/javase/6/docs/api/java/beans/XMLEncoder.htmlhttp://download.oracle.com/javase/6/docs/api/java/beans/XMLDecoder.html

EDIT:チュートリアルここに:http://java.sun.com/products/jfc/tsc/articles/persistence4/

+0

だから私は、プログラムで使用されるクラスのほとんどを含むJTabbedPaneを持っています。 xmlencoderを作成してJTabbedPaneオブジェクトを作成すると、そのコンポーネントに含まれるすべてのコンポーネントもファイルに書き込まれますか? –

+0

私は 'JTabbedPane'自体を書いていません。モデルをGUIコンポーネントから分離する必要があります。私はあなたが必要とするすべての属性を含む 'UserInputBean'のようなものを作成します。 – home

関連する問題