如何使用我的应用程序中的java.util.Properties-文件来记住上次的状态。我希望我的应用程序是在与上次closed.This相同的位置和大小打开的,这是我的代码的一部分:
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Infinity");
v demo = new v();
frame.setContentPane(demo.createContentPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setSize(new Dimension(740, 480));
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Properties prop = new Properties();
// add some properties
prop.setProperty("Height", "200");
prop.put("Width", "1500");
// print the list
try {
// store the properties list in an output stream
prop.store(System.out, "PropertiesDemo");
} catch (IOException ex) {
ex.printStackTrace();
}
createAndShowGUI();
}
});
}}发布于 2014-02-13 21:02:55
是的,只需调用setProperty方法即可。然后,在你关闭之前,打电话给保存。
启动时,以您已经使用的方式调用加载。
甚至比所有这些更好的是,使用首选项。
https://stackoverflow.com/questions/21765337
复制相似问题