- class MyCanvas extends Canvas
- {
- private Image img;
- MyCanvas(Image img)
- {
- this.img = img;
- }
- public void paint(Graphics g)
- {
- //g.drawImage(img, 100,100, this);
- g.draw3DRect(1, 1, 12, 12, true);
- }
- public void drawSomething()
- {
- Graphics g = this.getGraphics();//为什么这里返回null?
- //g.drawImage(img, 12, 12, this);
- g.draw3DRect(2, 2, 22, 22, true);
- }
- }
复制代码 简单的实现了一个Canvas的子类,并在JFrame中调用了,但提示如上异常。
|