现在我学到paintComponent方法了,我需要在别的类中画图,并添加到界面中,只靠paintComponent是不够的,有没有什么方法能将画出来的东西加到主画板中呀?求拯救!

解决方案 »

  1.   

    把主面板的Graphics对象传给要绘制的那个类的对象。
      

  2.   

    在写paintComponent()方法时是这样写的:
    protected void paintComponent(Graphics g){
    super.paintComponent(g);
             //绘画主体
    }
    这个g传不过去呀
      

  3.   

    你可以考虑,在“别的类”中,直接把你想绘制的东西绘制在一个 BufferedImage 中
    然后直接在你重写了 paintComponent 的那个控件中,绘制这个 BufferedImage
      

  4.   

    在写paintComponent()方法时是这样写的:
    protected void paintComponent(Graphics g){
    super.paintComponent(g);
             //绘画主体
    }
    这个g传不过去呀
    作为一个方法参数不就传过去了,方法放在super.paintComponent(g);后面