Wednesday 26 October 2011

Programming Java Applet Help?

My assignment is basically to create multiple objects in a java applet that form a picture. The picture must then appear in a random place at a random size. I could really use some help!



Ok, so I got the picture drawn in java, in a static place and size.

Here's an example of what I did ( with a random picture i don't know how this one would look):

STARTED OUT WITH JUST THE PICTURE

page.drawOval (100, 200, 250, 250);

page.drawOval (50, 100, 140, 140);



OK SO THAT WORKED THEN I ADDED RANDOM MOVEMENT:

I created 2 randoms, a and b

page.drawOval (100 + a, 200 + b, 250, 250);

page.drawOval (50 + a, 100 + b, 140, 140);



It was the same size every time but random movement and the picture stayed together



Then, I tried to change the size and THE PICTURE FELL APART!



I put:

3 randoms, a, b, and c

page.drawOval (100 + a, 200 + b, 250 * c, 250 * c);

page.drawOval (50 + a, 100 + b, 140 * c, 140 * c);



I THOUGHT THAT THIS WOULD KEEP THE PICTURE INTACT AND SWITCH THE SIZE BUT ALTHOUGH THE SIZE WAS RANDOMIZED THE PARTS OF THE PICTURE ARE NO LONGER FORMING THE PICTURE, JUST RANDOMLY SCATTERED AROUND THE PAGE!!!



HELP PLEASE??!!
Programming Java Applet Help?
Are you getting a different random value for %26quot;a%26quot;, %26quot;b%26quot;, and %26quot;c%26quot; between calls to the drawOval method?



// define limits for your X/Y random range

private static int UPPERX = 1024;

private static int UPPERY = 768;

// define limit for scaling

private static int SCALE = 5;



Random randomGenerator = new Random();



// Guessing you are wanting some sort of loop here

for (int i = 0; i %26lt; myLimit; i++)

{

int a = randomGenerator.nextInt(UPPERX);

int b = randomGenerator.nextInt(UPPERY);

int c = randomGenerator.nextInt(SCALE);



System.out.println(%26quot;a = %26quot; + a + %26quot;; b = %26quot; + b + %26quot;; c = %26quot; + c);

page.drawOval(100 + a), 200+b, 250 * c, 250 * c);



// Unless you want to use the same %26quot;a%26quot;, %26quot;b%26quot;, and %26quot;c%26quot; for the next draw, get a new random value for them.

int a = randomGenerator.nextInt(UPPERX);

int b = randomGenerator.nextInt(UPPERY);

int c = randomGenerator.nextInt(SCALE);



System.out.println(%26quot;a = %26quot; + a + %26quot;; b = %26quot; + b + %26quot;; c = %26quot; + c);

page.drawOval(100 + a), 200+b, 250 * c, 250 * c);

}