So I'm trying to get this rectangle to perform a jumping motion every time I hit the space bar. When I tap the space bar the motion is fine. It goes up and comes back down, but the motion isn't very fluid. It just immediately comes up to the high point and then immediately goes back to the ground. How do I fix this? Here is the code for the jumping motion (Jump is what is called upon pressing the space key and Fall is on the release of the space key) :
class Jump extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
while(time<2.5)
{
time+=0.1;
py-=5-(2*(time));
if(py>=300)
{
py=300;
py-=0;
}
repaint();
System.out.println(time);
}
}
}
class Fall extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
while(time>0)
{
time-=0.1;
py+=5-(2*(time));
if(py>=300)
{
py=300;
py-=0;
}
repaint();
}
}
}