For Programmers: Free Programming Magazines  


Home > Archive > Java Help > February 2006 > Polygon random location and random radius









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Polygon random location and random radius
andrewtitus@alltel.net

2006-02-22, 3:57 am

Iam trying to draw 10 stars using polygons. The stars have to be at random
locations and have a random radius. I read in 10 random xPoints and yPoints
and set the number of points to a random number up to 6. When I run the
program I get error ¼§ÏRandomStarPanel.java:52:
drawPolyline(int[],int[],int) in java.awt.Graphics cannot be applied to
(int,int,int)

Can someone point me in the right direction on this not only the error but
an idea of how to impliment problem.

Thank You,
Andy



import javax.swing.*;
import java.util.*;

public class RandomStarPanel extends JPanel
{
final int MAXPOINTS = 6;
int width,height,nPoints;
int[] Radius = new int[10];
int[][] Locations = new int[10][10];
int[] xPoints = new int[MAXPOINTS];
int[] yPoints = new int[MAXPOINTS];


public RandomStarPanel()
{

setBackground (Color.black);
setPreferredSize (new Dimension(400,400));
RandomNumberGenerator();


} //end RandomStarpanel()

public void RandomNumberGenerator()
{

width = getSize ().width;
height = getSize ().height;

Random generator = new Random();

nPoints = generator.nextInt(MAXPOINTS);

for (int xNumb = 0; xNumb < Locations.length; xNumb++){
for (int yNumb = 0; yNumb < Locations[xNumb].length; yNumb++)
Locations[xNumb][yNumb] =generator.nextInt(100);

}


}

public void paintComponent(Graphics page)
{
super.paintComponent(page);
page.setColor(Color.white);

for (int xNumb = 0; xNumb < Locations.length; xNumb++){
for (int yNumb = 0; yNumb < Locations[xNumb].length; yNumb++)
page.drawPolyline(xNumb,yNumb,nPoints);

}








} //end paintComponent()

} // end RandomStarPanel
Paul Hamaker

2006-02-22, 7:59 am

page.drawPolyline(xNumb,yNumb,nPoints);
First two parameters have to be arrays.
--------
Paul Hamaker, SEMM
http://javalessons.com

andrewtitus@alltel.net

2006-02-22, 7:59 am

I want to thank you for the help. It works. Well it draws the lines but not
the shapes I want. I need to draw 10 stars in random location with random
radius. Is there a way to do this? Can you give me some ideas on this?

Thank You,
Andy

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class RandomStarPanel extends JPanel
{
final int MAXPOINTS = 6;
int width,height,nPoints;
int[] Radius = new int[10];
int[][] Locations = new int[10][10];
int[] xPoints = new int[MAXPOINTS];
int[] yPoints = new int[MAXPOINTS];


public RandomStarPanel()
{

setBackground (Color.black);
setPreferredSize (new Dimension(400,400));
RandomNumberGenerator();


} //end RandomStarpanel()

public void RandomNumberGenerator()
{

width = getSize ().width;
height = getSize ().height;

Random generator = new Random();

nPoints = generator.nextInt(MAXPOINTS);

for (int xNumb = 0; xNumb < Locations.length; xNumb++){
for (int yNumb = 0; yNumb < Locations[xNumb].length; yNumb++)
Locations[xNumb][yNumb] =generator.nextInt(400);

}


}

public void paintComponent(Graphics page)
{
super.paintComponent(page);
page.setColor(Color.white);

for (int xNumb = 0; xNumb < Locations.length; xNumb++){
for (int yNumb = 0; yNumb < Locations[xNumb].length; yNumb++)
//
page. fillPolygon(Locations[xNumb],Locations[y
Numb],Locations.length);

page. drawPolyline(Locations[xNumb],Locations[
yNumb],Locations.length);
}

} //end paintComponent()

} // end RandomStarPanel
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com