菜鸟求助,系统配置图片显示程序???

RocketGor RocketGor 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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
这是配置文件的内容
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
RocketGor
Java SE 62,620 成员 307,251 内容