我有一个程序需要保存 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 等中的一些值然后关闭程序并重新打开它时,数据没有保存。谁能解释为什么这不起作用或对我需要做的不同提出一些建议?谢谢你。