I have an error when I add in another ball. The colors are the same how would it be possible to change the colors of the balls seperately when they are on the same screen. When I added the other ball in when one hit the edge the second one changed color aswell. Another thing: How would I change the Background color?
// The "ScreenSaver" class.
import java.awt.*;
import hsa.Console;
public class ScreenSaver
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
int a = 1;
int x, y, dx, dy;
x = 1;
y = 1;
double rand;
c.print ("How many pixels do you want the ball to move sideways? (int only)");
dx = c.readInt ();
c.print ("How many pixels do you want the ball to move up and down? (int only)");
dy = c.readInt ();
while (a == 1)
{
c.clear ();
c.fillOval (x, y, 40, 40);
if ((x + dx < 0) || (x + dx + 40 > c.getWidth ()))
{
dx = -dx;
rand = Math.random();
if (rand > .9){
c.setColor (Color.red);
}
else if (rand > .8){
c.setColor (Color.blue);
}
else if (rand > .7){
c.setColor (Color.green);
}
else if (rand > .6){
c.setColor (Color.magenta);
}
else if (rand > .5){
c.setColor (Color.pink);
}
else if (rand > .4){
c.setColor (Color.orange);
}
else if (rand > .3){
c.setColor (Color.cyan);
}
else if (rand > .2){
c.setColor (Color.yellow);
}
else if (rand > .1){
c.setColor (Color.gray);
}
else {
c.setColor (Color.black);
}
}
if ((y + dy < 0) || (y + dy + 40 > c.getHeight ()))
{
dy = -dy;
rand = Math.random();
if (rand > .9){
c.setColor (Color.red);
}
else if (rand > .8){
c.setColor (Color.blue);
}
else if (rand > .7){
c.setColor (Color.green);
}
else if (rand > .6){
c.setColor (Color.magenta);
}
else if (rand > .5){
c.setColor (Color.pink);
}
else if (rand > .4){
c.setColor (Color.orange);
}
else if (rand > .3){
c.setColor (Color.cyan);
}
else if (rand > .2){
c.setColor (Color.yellow);
}
else if (rand > .1){
c.setColor (Color.gray);
}
else {
c.setColor (Color.black);
}
}
for (int i = 0 ; i < 5000000 ; i++)
;
c.clear ();
x = x + dx;
y = y + dy;
}
// Place your program here. 'c' is the output console
} // main method
} // ScreenSaver class
Thanks for the help.