Results 1 to 2 of 2
Thread: Random Generator
- 12-03-2007, 05:29 PM #1
Member
- Join Date
- Nov 2007
- Location
- Hershey, PA
- Posts
- 13
- Rep Power
- 0
Random Generator
I need help with the thing to add to my code to make all the eclipses into circles and make them all random colors.
/*
Jordan Nissley
Boxes.java
*/
import java.applet.Applet;
import java.awt.*;
import java.util.Random;
public class Boxes extends Applet
{
//-----------------------------------------------------------------
// Paints boxes of random width and height in a random location.
// Narrow or short boxes are highlighted with a fill color.
//-----------------------------------------------------------------
public void paint(Graphics page)
{
final int NUM_BOXES = 100, THICKNESS = 5, MAX_SIDE = 50;
final int MAX_X = 350, MAX_Y = 250;
int x, y, width, height;
setBackground (Color.black);
Random generator = new Random();
for (int count = 0; count < NUM_BOXES; count++)
{
x = generator.nextInt (MAX_X) + 1;
y = generator.nextInt (MAX_Y) + 1;
width = generator.nextInt (MAX_SIDE) + 1;
height = generator.nextInt (MAX_SIDE) + 1;
page.setColor (Color.white);
page.drawOval (x, y, width, height);
}
}
}~Live as if you were to die tomorrow.~
- 12-03-2007, 06:43 PM #2
Java Code:// <applet code="BoxesApplet" width="400" height="400"></applet> import java.applet.Applet; import java.awt.*; import java.util.Random; public class BoxesApplet extends Applet { final int NUM_BOXES = 100, THICKNESS = 5, MAX_SIDE = 50; final int MAX_X = 350, MAX_Y = 250; Random generator; public void init() { setBackground (Color.black); generator = new Random(); } //----------------------------------------------------------------- // Paints boxes of random width and height in a random location. // Narrow or short boxes are highlighted with a fill color. //----------------------------------------------------------------- public void paint(Graphics page) { Graphics2D g2 = (Graphics2D)page; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x, y, width, height; for (int count = 0; count < NUM_BOXES; count++) { x = generator.nextInt (MAX_X) + 1; y = generator.nextInt (MAX_Y) + 1; width = generator.nextInt (MAX_SIDE) + 1; height = generator.nextInt (MAX_SIDE) + 1; int diam = Math.max(width, height); page.setColor (getColor()); page.drawOval (x, y, diam, diam); } } private Color getColor() { return new Color(generator.nextInt(0xffffff)); } }
Similar Threads
-
Database Bean Generator 2.1.4
By Java Tip in forum Java SoftwareReplies: 0Last Post: 04-15-2008, 06:55 PM -
Java GetOpt Generator 0.81.1
By JavaBean in forum Java SoftwareReplies: 0Last Post: 03-10-2008, 01:58 PM -
random numbers without random class`
By carlos123 in forum New To JavaReplies: 4Last Post: 01-17-2008, 10:44 PM -
Big Faceless Report Generator 1.1.38
By JavaBean in forum Java SoftwareReplies: 0Last Post: 10-25-2007, 04:20 PM -
Dragon parser generator 1.2.9
By Jamie in forum Java SoftwareReplies: 0Last Post: 06-17-2007, 03:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks