Original Post
I was wondering if java animation has to be choppy if you are not using bindings to some grapichs library?
For some reason the following code gives a fairly smooth animation, but sometimes it stops and the animation gets choppy.
This code is placed inside a class that inherits from JPanel and is invoked every 40 ms by a javax.swing.Timer.
public void paintComponent( Graphics g ){
super.paintComponent( g );
Graphics2D gBuffer=(Graphics2D) g;
gBuffer.drawLine( 0, 25, 392, 25 );
gBuffer.drawLine( 0, 250, 392, 250 );
gBuffer.drawString( "Score: "+score, 150, 20 );
gBuffer.fillRect( ball.getXpos1(), ball.getYpos1(), ball.size(), ball.size() );
gBuffer.fillRect( paddOne.getXpos1(), paddOne.getYpos1(), paddOne.getDepth(), paddOne.getWidth() );
gBuffer.fillRect( paddTwo.getXpos1(), paddTwo.getYpos1(), paddTwo.getDepth(), paddTwo.getWidth() );
}
Are there any way to make this paint code faster or is my computer just not fast enough? By the way I am using a P3 800 MHz with 128 Mb RAM.