Results 1 to 2 of 2
  1. #1
    padutch2 is offline Member
    Join Date
    Nov 2007
    Location
    Hershey, PA
    Posts
    13
    Rep Power
    0

    Default 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.~

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    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

  1. Database Bean Generator 2.1.4
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-15-2008, 06:55 PM
  2. Java GetOpt Generator 0.81.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 03-10-2008, 01:58 PM
  3. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 10:44 PM
  4. Big Faceless Report Generator 1.1.38
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-25-2007, 04:20 PM
  5. Dragon parser generator 1.2.9
    By Jamie in forum Java Software
    Replies: 0
    Last Post: 06-17-2007, 03:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •