在A类中实例化了一个简易窗口,然后安排在3秒之后显示一张图片,为什么没有出现呢?用了repaint方法没有用classA{publicstaticvolatileintwidth;publicstaticvolatileintheight;publi...
在A类中实例化了一个简易窗口,然后安排在3秒之后显示一张图片,为什么没有出现呢?用了repaint方法没有用
class A{
public static volatile int width;
public static volatile int height;
public boolean isFinished=false;
public A() {
JFrame jf=Frame_Gen.Fr_G("欢迎使用", false, 600, 400);
jf.setSize(600, 400);
jf.setLocation(250, 250);
jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
jf.setResizable(false);
//Container c=jf.getContentPane();
width=jf.getWidth();
height=jf.getHeight();
//jf.add(new pic());
Thread t=new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
jf.add(new ppp());
}
});
t.start();
}
class ppp extends Canvas{
/**
*
*/
private static final long serialVersionUID = 1L;
public void paint(Graphics g) {
Graphics2D g1=(Graphics2D)g;
super.paint(g1);
Image image=Toolkit.getDefaultToolkit().getImage("C:\\Users\\Administrator\\Pictures\\Camera Roll\\2.jpeg");
g1.drawImage(image, 0, 0, width, height, this);
}
}
class pic extends Canvas{
/**
*
*/
private static final long serialVersionUID = 1L;
public void paint(Graphics g) {
Graphics2D g1=(Graphics2D)g;
super.paint(g1);
//URL url=A.class.getResource("1.jpg");
//Image image=Toolkit.getDefaultToolkit().getImage(url);
Image image=Toolkit.getDefaultToolkit().getImage("C:\\Users\\Administrator\\Pictures\\Camera Roll\\1.jpg");
g1.drawImage(image, 0, 0, width, height, this);
}
}
}
展开