I have a homework assignment that is asking me to create a JFrame that is filled with randomly colored circles
I have a bit of code already completed, but cannot wrap my head around the "if" statement and how to use it properly to execute this bit of code.
Below is my code and I am at a loss as to what to do next.
/*
*/
package p03looping;
import java.awt.Color;
import java.awt.Graphics;
public class ColorDots extends javax.swing.JFrame {
public static final int CIRCLE_WIDTH = 100;
public static final int CIRCLE_HEIGHT = 100;
public static final int CIRCLE_COUNT = 35;
public static final int CIRCLE_RIGHT_OFFSET = 120;
public static final int CIRCLE_TOP_OFFSET = 40;
public static final int CIRCLE_SPACE = 10;
public ColorDots(String title) {
setTitle("Colored Dots");}
@Override
public void paint(Graphics canvas) {
super.paint(canvas);
int canvas_width = getWidth();
int canvas_height = getHeight();
// Background color = black
canvas.setColor(Color.BLACK);
canvas.fillRect(0, 0, canvas_width, canvas_height);
// Drawing circles with random colors
int circleX;
int circleY;
int red = (int) (Math.random( )*256);
int green = (int)(Math.random( )*256);
int blue = (int)(Math.random( )*256);
Color randomColor = new Color(red, green, blue);
canvas.setColor(randomColor);
for (int circleCount=0; circleCount <= CIRCLE_COUNT; circleCount++)
{
int space = canvas_width-CIRCLE_WIDTH;
canvas.fillOval(canvas_width-CIRCLE_RIGHT_OFFSET, CIRCLE_TOP_OFFSET,
CIRCLE_WIDTH, CIRCLE_HEIGHT);
}
}
}

New Topic/Question
Reply



MultiQuote







|