import java.awt.Graphics;
import java.applet.Applet;
import java.awt.Color;
public class Main extends Applet implements Runnable
{
Thread t;
int x=500;
int y=745;
@Override
public void init()
{
setBackground(Color.black);
}
@Override
public void start()
{
if(t==null)
{
t=new Thread(this);
t.start();
}
}
@Override
public void stop()
{
if(t!=null)
t.stop();
}
public void run()
{
while(true)
{
if(y<250) //
{ //
y=y+5; //
} //
else
{
y=y-5;
}
repaint();
try
{
Thread.sleep(40);
}
catch(InterruptedException ex)
{}
}
}
@Override
public void paint(Graphics g)
{
g.setColor(Color.red);
g.fillOval(x,y,50,50);
}
}
i have a problem in the commented line wham am i trying to do is first display the circle at the location and make it move upwards by reducing it by five and that is working fine...so than what do i want is after reaching certain position am making 250 i want the ball to return back so i just made it opposite by adding 5 now why is the logic not working ......please explain me the logic.....every part of the code is working fine beside that thanks