RainbowPanel

RainbowPanel - public void paintComponent (Graphics page) {...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// *********************************************** // File: Rainbow.java // // Purpose: Draw a rainbow with random colors // *********************************************** import javax.swing.JPanel; import java.awt.*; import java.util.Random; public class RainbowPanel extends JPanel { //-------------------------------------------- // Sets up the rainbow panel. //-------------------------------------------- public RainbowPanel () { // Make the pretty blue sky setBackground (Color.cyan); // Set the panel size setPreferredSize (new Dimension(600, 400)); } //-------------------------------------------- // Paints the rainbow. //--------------------------------------------
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public void paintComponent (Graphics page) { final int ARCS = 6; int x = 150; int y = 150; int height = 300; int width = 300; int red, green, blue; // Randomize Random generator = new Random(); for (int count = 0; count < ARCS; count++) { red = generator.nextInt(256); green = generator.nextInt(256); blue = generator.nextInt(256); Color arcColor = new Color (red, green, blue); // Draw arcs page.setColor(arcColor); page.fillArc (x, y, width, height, 0, 180); x += 15; y += 15; width -= 30; height -= 30; } //make the inside sky blue page.setColor(Color.cyan); page.fillArc (x, y, width, height, 0, 180); } }...
View Full Document

Page1 / 2

RainbowPanel - public void paintComponent (Graphics page) {...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online