我試圖在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
這是功課嗎? –