AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Polygon random location and random radius

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed Feb 22, 2006 10:12 am    Post subject: Polygon random location and random radius Reply with quote



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





PostPosted: Wed Feb 22, 2006 11:12 am    Post subject: Re: Polygon random location and random radius Reply with quote



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






PostPosted: Wed Feb 22, 2006 12:12 pm    Post subject: Re: Polygon random location and random radius Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.