你可以看一下api,上面写着
Returns:
an off-screen drawable image, which can be used for double buffering. The return value may be null if the component is not displayable. 
如果你调用一下isDisplayable(),就会发现返回的是false。因此这时image肯定是null。
你可以在JPanel里用createImage(),然后把这个JPanel放到你想要的地方。

解决方案 »

  1.   

    谢谢
    大致意思我明白了
    在frame setvisible 后产生的image不再为null,
    但是frame表面还是无法无法看到图像。
    我画图的方法是这样的:
    void mousePressed(MouseEvent e) {
       Point p=e.getPoint();
       Graphics g=imag.getGraphics();
       g.setColor(currentC);
       g.fillOval((int)(p.getX()-r),(int)(p.getY()-r),2*r,2*r);
       repaint();
      }public void paintComponent(Graphics g)
      {
         g.drawImage(imag,0,0,this);
    }