 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Wed Feb 22, 2006 10:12 am Post subject: Polygon random location and random radius |
|
|
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 |
|
| Back to top |
|
 |
Paul Hamaker Guest
|
Posted: Wed Feb 22, 2006 11:12 am Post subject: Re: Polygon random location and random radius |
|
|
page.drawPolyline(xNumb,yNumb,nPoints);
First two parameters have to be arrays.
--------
Paul Hamaker, SEMM
http://javalessons.com |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Feb 22, 2006 12:12 pm Post subject: Re: Polygon random location and random radius |
|
|
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[yNumb],Locations.length);
page.drawPolyline(Locations[xNumb],Locations[yNumb],Locations.length);
}
} //end paintComponent()
} // end RandomStarPanel |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|