Draw a rainbow-use what you know about colors, pixels, and drawing operations to draw a rainbow.

What will be an ideal response?

```
public void drawRainbow ( )
{
Graphics g = this.getGraphics ( ) ;
int height = this.getHeight ( ) ;
int width = this.getWidth ( ) ;
int diff = width / 15 ;
int halfDiff = diff / 2 ;
int x = 0 ;
int y = 0 ;
// draw the red arc
g . set Color ( Color .RED) ;
g . fil lArc (x , y , width , height , 0 , 1 8 0 ) ;
// draw the orange arc
width = width - diff ;
height = height - diff ;
x = x + halfDiff ;
y = y + h alfDiff ;
g . set Color (new Color ( 255, 102, 0 ) ) ;
g. fill Arc (x , y , width , height , 0 , 180 ) ;
// draw the yellow arc
width = width - diff ;
height = height - diff ;
x = x + halfDiff ;
y = y + halfDiff ;
g. set Color (Color .YELLOW) ;
g. fill Arc (x , y , width , height , 0 , 180 );
// draw the green arc
width = width - diff ;
height = height - diff;
x = x + half Diff;
y = y + half Diff;
g. set Color (Color .GREEN) ;
g. fill Arc (x , y , width , height , 0 , 1 8 0 ) ;
// draw the blue arc
width = width - diff;
height = height - diff ;
x = x + halfDiff ;
y = y + halfDiff ;
g. set Color ( Color .BLUE) ;
g. fill Arc (x , y , width , height , 0 , 180 ) ;
// draw the purple arc
width = width - diff ;
height = height - diff ;
x = x + halfDiff ;
y = y + halfDiff ;
g. set Color (new Color ( 153 , 0 , 204 ) ) ;
g. fill Arc (x , y , width , height , 0 , 180 ) ;
// draw the white arc
width = width - diff;
height = height - diff;
x = x + halfDiff ;
y = y + halfDiff ;
g. set Color ( Color .WHITE) ;
g. fill Arc (x , y , width , height , 0 , 180 ) ;
}
```

Computer Science & Information Technology

You might also like to view...

With some objects, it is necessary to ungroup them multiple times

Indicate whether the statement is true or false

Computer Science & Information Technology

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

1. In a Swing program, throwing an uncaught exception may leave the program in an unpredictable state. 2. A window listener must define all the method headings in the WindowListener interface, even if some are trivial implementations.

Computer Science & Information Technology