以下代码执行但我的框架窗口无法获取图像,如何解决此问题?
import java.awt.*;
import java.awt.event.*;
public class AwtImage extends Frame
{
Image img;
public static void main(String[] args)
{
AwtImage ai = new AwtImage();
}
public AwtImage()
{
super("Image Frame");
MediaTracker mt = new MediaTracker(this);
img = Toolkit.getDefaultToolkit().getImage("icon_confused.gif");
mt.addImage(img,10);
setSize(400,400);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
dispose();
}
});
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
if(img != null)
g.drawImage(img, 100, 100, this);
else
g.clearRect(0, 0, getSize().width, getSize().height);
}
}
我正在版本jdk 1.6
中运行这个Graphics类是否有任何问题