genics
11-21-2007, 07:38 AM
Hey folks,
I'm trying get objects in a drawing window to move around and I've encountered some problems.
Here's my code:
import element.*;
import java.awt.Color;
public class attemp4
{
public static void main(String[] args)
{
DrawingWindow drawWin = new DrawingWindow(500,500);
for(int i = 0; i < 500; i++)
{
Rect box = new Rect(0,i,100,1);
drawWin.setForeground(Color.blue);
drawWin.fill(box);
waitNseconds(1);
}
for(int i = 500; i > 0; ++i)
{
Rect box2 = new Rect(100,i,100,100);
drawWin.setForeground(Color.yellow);
drawWin.fill(box2);
waitNseconds(1);
}
}
public static void wait1second()
{
long now = System.currentTimeMillis();
long then = now + 1;
while (System.currentTimeMillis() < then){ }
}
public static void waitNseconds(int num)
{
for (int i= 0; i < num; i++)
{
wait1second();
}
}
}
Basically the first for loop makes the first rectangle go down the page correctly, however I want the second rectangle (the yellow one) to go up instead of down.
How would I go about doing this properly?
Cheers!
I'm trying get objects in a drawing window to move around and I've encountered some problems.
Here's my code:
import element.*;
import java.awt.Color;
public class attemp4
{
public static void main(String[] args)
{
DrawingWindow drawWin = new DrawingWindow(500,500);
for(int i = 0; i < 500; i++)
{
Rect box = new Rect(0,i,100,1);
drawWin.setForeground(Color.blue);
drawWin.fill(box);
waitNseconds(1);
}
for(int i = 500; i > 0; ++i)
{
Rect box2 = new Rect(100,i,100,100);
drawWin.setForeground(Color.yellow);
drawWin.fill(box2);
waitNseconds(1);
}
}
public static void wait1second()
{
long now = System.currentTimeMillis();
long then = now + 1;
while (System.currentTimeMillis() < then){ }
}
public static void waitNseconds(int num)
{
for (int i= 0; i < num; i++)
{
wait1second();
}
}
}
Basically the first for loop makes the first rectangle go down the page correctly, however I want the second rectangle (the yellow one) to go up instead of down.
How would I go about doing this properly?
Cheers!