自己创建一个容器,然后继承。在你自己的容器中添加,如下:
import java.awt.*;
import java.net.URL;
class MyFrm extends Frame
{
private String ClassPath;
private String img_url;
private Image img;
public MyFrm()
{
super();
}
public MyFrm(String str,int W,int H,String Cp,String Iurl)
{
super(str);
setSize(W,H);
img_url=Iurl;
ClassPath=Cp;
}
public void paint(Graphics g)
{
URL url=null;
try
{
url=Class.forName(ClassPath).getResource(img_url);
}
catch(Exception e){System.out.println("can't get file");}
img=getToolkit().getImage(url);
MediaTracker mt=new MediaTracker(this);
mt.addImage(img,1);
try
{
mt.wait();
mt.checkAll();
}
catch(Exception e) {}
g.drawImage(img,((int)this.getSize().getWidth()-200)/2,((int)this.getSize().getHeight()-150)/2,this);
}
}