在awt中添加图像
我试图在 GridBagLayout 单元格之一中添加图像。但我无法实现它。
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;
}
}
请帮忙。
提前致谢
I was trying to add an image in one of GridBagLayout cells. But i am not able to achieve it.
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;
}
}
Please help.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哈?!?
Huh?!?
使用 Applet 类的
Applet.getImage()
方法。Use
Applet.getImage()
method of the Applet class.