这个程序怎么理解,请达人知道以下

来源:百度知道 编辑:UC知道 时间:2024/06/06 04:40:35
代码如下
public void paintComponent( Graphics g )
{
super.paintComponent( g );

Shape current;

for ( int i = 0; i < shapes.size(); i++ ) {
current = ( Shape ) shapes.elementAt( i );
current.draw( g );
}
}

public void paintComponent( Graphics g ) //重写组件
{
super.paintComponent( g ); //调用父类的构造方法

Shape current; //申明current属于Shape类

for ( int i = 0; i < shapes.size(); i++ ) { //从零到shape的大小进行循环
current = ( Shape ) shapes.elementAt( i ); //将shapes转换成Shape类型,并将该组件加入到current中
current.draw( g ); //画出current
}
}

总体来说:就是重写paint方法。