Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2007, 06:29 PM
Member
 
Join Date: Nov 2007
Location: Hershey, PA
Posts: 13
padutch2 is on a distinguished road
Send a message via AIM to padutch2
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.~
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-03-2007, 07:43 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,191
hardwired is on a distinguished road
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)); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Bean Generator 2.1.4 Java Tip Java Announcements 0 04-15-2008 07:55 PM
Java GetOpt Generator 0.81.1 JavaBean Java Announcements 0 03-10-2008 02:58 PM
random numbers without random class` carlos123 New To Java 4 01-17-2008 11:44 PM
Big Faceless Report Generator 1.1.38 JavaBean Java Announcements 0 10-25-2007 05:20 PM
Dragon parser generator 1.2.9 Jamie Java Announcements 0 06-17-2007 04:36 PM


All times are GMT +3. The time now is 10:53 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org