利用properties文件记录界面的大小和位置
来源:互联网 发布:淘宝卖家生存现状 编辑:程序博客网 时间:2024/06/10 16:01
class PropertiesFrame extends JFrame {
public PropertiesFrame() {
String userDir = System.getProperty("user.home");
File propertiesDir = new File(userDir, ".coreJava");
if(!propertiesDir.exists()) {
propertiesDir.mkdir();
}
propertiesFile = new File(propertiesDir, "program.properties");
Properties defaultSetting = new Properties();
defaultSetting.put("left", "0");
defaultSetting.put("top", "0");
defaultSetting.put("width", "" + DEFAULT_WIDTH);
defaultSetting.put("height", "" + DEFAULT_HEIGHT);
defaultSetting.put("title", "");
settings = new Properties(defaultSetting);
if(propertiesFile.exists()) {
try {
FileInputStream in = new FileInputStream(propertiesFile);
settings.load(in);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
int left = Integer.parseInt(settings.getProperty("left"));
int top = Integer.parseInt(settings.getProperty("top"));
int width = Integer.parseInt(settings.getProperty("width"));
int height = Integer.parseInt(settings.getProperty("height"));
setBounds(left, top, width, height);
String title = settings.getProperty("title");
if("".equals(title)) {
title = JOptionPane.showInputDialog("Please input a frame title:");
}
if(null == title) {
title = "";
}
setTitle(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
settings.put("left", "" + getX());
settings.put("top", "" + getY());
settings.put("width", "" + getWidth());
settings.put("height", "" + getHeight());
settings.put("title", getTitle());
try {
FileOutputStream out = new FileOutputStream(propertiesFile);
settings.store(out, "program properties");
out.close();
} catch (Exception e) {
e.printStackTrace();
}
System.exit(0);
}
});
}
public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 200;
private File propertiesFile;
private Properties settings;
}
public PropertiesFrame() {
String userDir = System.getProperty("user.home");
File propertiesDir = new File(userDir, ".coreJava");
if(!propertiesDir.exists()) {
propertiesDir.mkdir();
}
propertiesFile = new File(propertiesDir, "program.properties");
Properties defaultSetting = new Properties();
defaultSetting.put("left", "0");
defaultSetting.put("top", "0");
defaultSetting.put("width", "" + DEFAULT_WIDTH);
defaultSetting.put("height", "" + DEFAULT_HEIGHT);
defaultSetting.put("title", "");
settings = new Properties(defaultSetting);
if(propertiesFile.exists()) {
try {
FileInputStream in = new FileInputStream(propertiesFile);
settings.load(in);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
int left = Integer.parseInt(settings.getProperty("left"));
int top = Integer.parseInt(settings.getProperty("top"));
int width = Integer.parseInt(settings.getProperty("width"));
int height = Integer.parseInt(settings.getProperty("height"));
setBounds(left, top, width, height);
String title = settings.getProperty("title");
if("".equals(title)) {
title = JOptionPane.showInputDialog("Please input a frame title:");
}
if(null == title) {
title = "";
}
setTitle(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
settings.put("left", "" + getX());
settings.put("top", "" + getY());
settings.put("width", "" + getWidth());
settings.put("height", "" + getHeight());
settings.put("title", getTitle());
try {
FileOutputStream out = new FileOutputStream(propertiesFile);
settings.store(out, "program properties");
out.close();
} catch (Exception e) {
e.printStackTrace();
}
System.exit(0);
}
});
}
public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 200;
private File propertiesFile;
private Properties settings;
}
- 利用properties文件记录界面的大小和位置
- 利用Preferences类记录界面的位置和大小
- 记录窗口的位置和大小
- VB记录窗体的大小和位置
- properties位置文件
- Properties文件位置
- 单文档界面指定位置显示指定大小的文字(汉字和英文)
- 利用C#更专业的实现运行时调整控件大小和位置
- 利用C#更专业的实现运行时调整控件大小和位置
- MyBatis的jdbc.properties文件记录
- 更改获取到窗口句柄的游戏界面大小、位置
- MFC 界面部件大小位置自适应 EasySize的使用
- 设置GVIM的默认初试界面大小、启动位置
- MFC界面控件位置大小控制的EasySize使用说明
- 获取tomcat上properties文件的内容——方便文件存储位置的修改,解耦和
- 记录窗口位置与大小
- 改变浏览器窗口的大小和位置
- VC6调节控件的位置和大小
- Window下打开并读取文件的方法
- Linux下samba的安装与配置
- QList用法
- 图的邻接矩阵表示形式,DFS和BFS,最小生成树Prim和Kruscal,单源最短路径Dijkstra算法
- android中的进度条processBar
- 利用properties文件记录界面的大小和位置
- STL - for_each 简单应用
- cudaEncode编码详细过程
- 腾讯实习生笔试到面试的经历
- android中的单选列表
- illegalargumentexception: view not attached to window manager
- 近期关注
- 电话号码规则
- jboss get请求中文乱码问题的解决[zt]