菜鸟求助,系统配置图片显示程序???
package frame;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.Properties;
/*返回一个属性的值*/
class SysConfig {//Properties 可保存在流中或从流中加载。属性列表中每个键及其对应值都是一个字符串。
static Properties props = new Properties();
static {
try {
//
props.load(SysConfig.class.getClassLoader().getResourceAsStream("config/windows.properties"));
} catch (IOException e1) {
e1.printStackTrace();
}
}
private SysConfig() {};
// getProperty(String key)在属性列表中搜索key键对应的属性
public static String getProperty(String key) {
return props.getProperty(key);
}
}
class ShowImage extends Frame{
Image image = null;
/*
* 定义窗口的宽度
* 定义窗口的高度
*/
int w= Integer.parseInt(SysConfig.getProperty("width"));
int h = Integer.parseInt(SysConfig.getProperty("high"));
private String filename = SysConfig.getProperty("URL");//由配置文件中获取文件路径
public ShowImage() { //主窗口
setLocation(300, 200);
this.setSize(w, h);//设置窗口大小
this.addWindowListener(new WindowAdapter() {//关闭窗口事件
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setTitle("林奇洛31号");
Draw draw = new Draw(this);
this.add(draw);//加入draw窗口
setResizable(false);
setVisible(true);
}
public void paint(Graphics g) {
//取得图片对象
Image image = getToolkit().getImage(filename);
//画图
g.drawImage(image, 0, 0, this);
}
}
public class Window {
public static void main(String[] args) {
new ShowImage();
}
}
为什么我运行程序后,显示的界面是没有图片的,要最小化,再打开来看得到图片啊?
width=350
high=510
URL=NBA.jpg
这是配置文件的内容