如何在我的应用程序中使用java.util.Properties文件来记住上次的状态。我希望我的应用程序在同一个地方打开,并且与上次关闭时的大小相同。这是我的代码的一部分:
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();
}
});
}}
答案 0 :(得分:0)