我试图在GridBagLayout单元格中添加一个图像。但我无法实现它。在awt中添加图像
public class imageInAwt extends Applet{
Panel p;
BufferedImage img;
public void init(){
setLayout(new GridBagLayout());
GridBagConstraints gbc =new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
try {
img = ImageIO.read(new File("settings.gif"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
add(new junaid(img),gbc);
gbc.gridy = GridBagConstraints.RELATIVE;
add(new Label("Junaid"),gbc);
}
}
class junaid extends Canvas {
Image img;
public junaid(Image img) {
this.img = img;
}
public void paint (Graphics g) {
BufferedImage image = null;
g.drawImage(image, 2, 3, null);
g.drawString("Junaid", 22, 16);
}
public void setImage (Image img){
this.img = img;
}
}
请大家帮忙。
在此先感谢
什么是HTML的位置和内容,以及图像的位置?该applet是否可供我们访问?在什么地址/网址? –
小程序类位于何处? – adatapost
这是功课吗? –