JTextFields、JComboBoxes などのすべてのものを保存する必要があるプログラムがあります。
私は、SingleFrameApplication クラスでこれを達成できると信じさせる例に出くわしました。
このプログラムには、シリアル化する場合に追跡する必要がある 1000 以上のコンポーネントがあります。
これが私がこれまでに持っているものです:
public class NewMain extends SingleFrameApplication{
//the file for the session to be saved to
String sessionFile = "sessionState.xml";
//Container is a class I made that extends a JPanel
Container container;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Application.launch(NewMain.class, args);
}
@Override
protected void startup() {
try {
//load the file
getContext().getSessionStorage().restore(getMainFrame(), sessionFile);
container = new Container(getContext());
show(container);
}
catch (Exception e) {
}
}
@Override
protected void shutdown() {
try {
//save to the file so we can open it later
getContext().getSessionStorage().save(getMainFrame(), sessionFile);
}
catch (Exception e) {
}
}
}
.jar ファイルを開いて実行し、JTextFields、JComboBoxes などの値を変更してから、プログラムを閉じて再度開くと、データが保存されませんでした。これが機能しない理由を説明したり、別の方法で行う必要があることについて提案したりできますか? ありがとうございました。