Find the error(s) in the following code. The rectangleArray is an instance variable of type ArrayList, which contains MyRectangle objects.

```
1 private void paintComponent( Graphics g )
2 {
3 superclass.paintComponent( g );
4 Iterator traverse = rectangleArray.iterator();
5
6 while ( traverse.hasMoreElements() )
7 {
8 MyRectangle currentRectangle = ( MyRectangle ) traverse.next();
9 currentRectangle.drawMyRectangle( g );
10
11 } // end while
12
13 } // end method paintComponent
```

To call the paintComponent method of the superclass, use keyword super. Also, in the while loop, to determine if there are remaining objects in the rectangleArray, use the hasNext method as opposed to the hasMoreElements method.
```
1 private void paintComponent( Graphics g )
2 {
3 super.paintComponent( g );
4 Iterator traverse = rectangleArray.iterator();
5
6 while ( traverse.hasNext() )
7 {
8 MyRectangle currentRectangle = ( MyRectangle ) traverse.next();
9 currentRectangle.drawMyRectangle( g );
10
11 } // end while
12
13 } // end method paintComponent
```

Computer Science & Information Technology

You might also like to view...

After entering a search string, press Enter or click the ________ icon next to the Search box in order to locate information on your search topic

A) small box B) magnifying glass C) question mark D) two overlapped boxes

Computer Science & Information Technology

Storage QoS can only be set on SCSI virtual hard disks.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology