public void insert ( Shape w , int beforeIndex ) { if ( ( beforeIndex < 0 ) || ( beforeIndex > size ) ) { throw new IndexOutOfBoundsException ( ) ; } // Realloc array if necessary (doubling). if ( size == array . length ) { Shape [ ] newArray = new Shape [ array . length * 2 ] ; for ( int i = 0 ; i < array . length ; ++ i ) { newArray [ i ] = array [ i ] ; } array = newArray ; } ++ size ; // Move all widgets after 'beforeIndex' back a slot. for ( int i = size - 1 ; i > beforeIndex ; -- i ) { array [ i ] = array [ i - 1 ] ; } array [ beforeIndex ] = w ; }
Inserts a widget before the specified index .