Swing的入门
一、重上次关闭位置启动窗体
(1)获取用户的根首选项节点: public static Preferences userRoot()
(2)向首选项保存整型数值: public abstract void putInt(Stirng key,int value)
参数:(1)key: 要与字符串形式的value相关联的键 (2)value: 要与key相关联的字符串形式的值
(3)获取首选项中的整型数数值: public abstract int getInt(String key,int def)
参数:(1)key:要作为int返回其关联值的键 (2)def:此首选项节点不具有与key相关联的值或无法将该关联值解释为int或者内部存储不可访问时要返回的默认值
1 public void windowClosing(WindowEvent e) 2 { 3 Preferences root = Preferences.userRoot(); //获得用户的首选项 4 Point location = getLocation(); //获得窗体的位置 5 root.putInt("locationX",location.x); //保存窗体的位置 6 root.putInt("locationY",location.y); 7 } 8 9 public void windowOpened(WindowEvent e) 10 { 11 Preferences root = Preferences.userRoot(); //获得用户的首选项 12 int x = root.getInt("locationX",100); //获得保存的位置 13 int y = root.getInt("locationY",100); 14 setLocation(x,y); //设置窗体的位置 15 }

浙公网安备 33010602011771号