- 论坛徽章:
- 0
|
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class testGraphics extends Canvas
{
Graphics gra;
Toolkit kit;
JFrame frame;
Image image,img;
int width=500, height=500;
public testGraphics(){
frame = new JFrame("test graphics");
frame.add(this);
frame.setSize(width,height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
kit = Toolkit.getDefaultToolkit();
img = kit.getImage("1.gif");
frame.setVisible(true);
image = createImage(width, height); //创建一副图片
try {
gra = image.getGraphics(); //获得此图片绘制对象
gra.setColor(Color.red);
gra.fillRect(0, 0, width, height);
gra.setColor(Color.black);
gra.drawString("此处绘制图片!",120,120);
gra.drawImage(img,120,210,this);
}
finally {
gra.dispose();
}
}
public void paint(Graphics g){
g.drawImage(image,0,0,this); //绘制指定图片
}
public static void main(String args[]){
testGraphics t = new testGraphics();
}
};
为什么图片绘制不出来?我知道在point()方法里可以绘制出来,
我想知道的是如果用上面的方法把图片绘制出来.. |
|