0% found this document useful (0 votes)
13 views1 page

Java Applet Rainbow Drawing Code

The document contains a Java program that creates a rainbow graphic using an applet. It defines constants for the number of colors and arcs, and uses nested loops to draw arcs of different colors on a black background. The program utilizes the Graphics class to render the arcs in specified colors, creating a visual representation of a rainbow.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Java Applet Rainbow Drawing Code

The document contains a Java program that creates a rainbow graphic using an applet. It defines constants for the number of colors and arcs, and uses nested loops to draw arcs of different colors on a black background. The program utilizes the Graphics class to render the arcs in specified colors, creating a visual representation of a rainbow.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//********************************************************************

// [Link] Author: Lewis and Loftus


//
// Solution to Programming Project 3.22 (page 173).
//********************************************************************
import [Link];
import [Link].*;
public class Rainbow extends Applet
{
private final int NUM_COLORS = 5;
private final int NUM_ARCS = 20;
private final int START_WIDTH = 50;
private final int START_HEIGHT = 40;
private final int START_X = 150 - START_WIDTH/2;
private final int START_Y = 200 - START_HEIGHT/2;
//-----------------------------------------------------------------
// Paints a rainbow.
//-----------------------------------------------------------------
public void paint(Graphics page)
{
int x = START_X, y = START_Y;
int width = START_WIDTH, height = START_HEIGHT;
setBackground ([Link]);
for (int color=1; color <= NUM_COLORS; color++)
{
switch (color)
{
case 1:
[Link] ([Link]);
break;
case 2:
[Link] ([Link]);
break;
case 3:
[Link] ([Link]);
break;
case 4:
[Link] ([Link]);
break;
case 5:
[Link] ([Link]);
}
for (int arcs = 1; arcs <= NUM_ARCS; arcs++)
{
[Link] (x, y, width, height, 0, 180);
x--;
y--;
width += 2;
height += 2;
}
}
}
}

You might also like