日期:2014-05-20  浏览次数:20666 次

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

------解决方案--------------------
把主面板的Graphics对象传给要绘制的那个类的对象。
------解决方案--------------------
你可以考虑,在“别的类”中,直接把你想绘制的东西绘制在一个 BufferedImage 中
然后直接在你重写了 paintComponent 的那个控件中,绘制这个 BufferedImage
------解决方案--------------------
引用:
Quote: 引用:

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

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

作为一个方法参数不就传过去了,方法放在super.paintComponent(g);后面