Animação em um JFrame - Muito lento

Fala galera,

Seguinte: estou fazendo um joguinho usando um JFrame e implementando o Double Buffer… o problema é que nele tenho algumas animações que está ficando muito lenta… :?

Alguém tem idéia de como posso melhor essa atualização dos quadros até mesmo usando outra coisa sem ser o JFrame?

[]s
Leo

Manda o codigo!

Falaê,

O código estava meio grande, então fiz uma parte isolada. Essa animação, se eu abrir o Windows Media Player junto… fica muito lento. Não sei se é do Java2D, a forma que fiz etc… da máquina acredito que não seja (meu cpu é um Athlon XP 2400+ com 256mb ram e placa de video ATI 128mb)

Se alguém tiver uma dica de como fazer isso, usando outras classes e tals agradeço…

t+

import java.awt.;
import java.awt.event.
;
import java.net.;
import javax.swing.
;
import java.awt.image.*;

public class teste extends JFrame implements Runnable {

Dimension offDimension;
Image offImage;
Graphics offGraphics;

Image estrelas;

private int largura = 600, altura = 600, x = 0, y = 0;
private float ag = 0;

private Thread tr = null;
	
public teste(){
	
	setSize(largura,altura);
	addWindowListener(new WindowAdapter(){
				public void windowClosing(WindowEvent e){
					System.exit(0);
				}
			}); 		
	start();
	
	estrelas = this.getToolkit().getImage("estrelas.gif");
	waitForImage(estrelas, this, 0);
}    

public void paint(Graphics g){
	update(g);
}

public void paintFrame(Graphics g){
	
	
	
	Graphics2D g2d;
	g2d = (Graphics2D)g;
	
	setBackground(new Color( 0, 0, 0));
	
	for(int a = -2100; a <= 2100; a+=600)
		for(int b = -2100; b <= 2100; b+=600)
			g.drawImage(estrelas,a+x,b+y,this);		
	

}

public void update(Graphics g) {
	
	Dimension d = size();

	if ((offGraphics == null)
 	|| (d.width != offDimension.width)
 	|| (d.height != offDimension.height)) {
    	offDimension = d;
    	offImage = createImage(d.width, d.height);
    	offGraphics = offImage.getGraphics();
	}

	offGraphics.setColor(getBackground());
	offGraphics.fillRect(0, 0,d.width, d.height);
	offGraphics.setColor(Color.black);

	paintFrame(offGraphics);

	g.drawImage(offImage, 0, 0, null);

}



public void start(){
	if (tr == null){
		tr = new Thread(this);
		tr.start();
	}
}	

public void run(){
	
	while (tr != null){
		
		x+=getCos(ag,7);
		y+=getSen(ag,7);
	
		ag+=1.75;			
		
		repaint();
		try{
			Thread.sleep(1000/30);
		} catch (InterruptedException e) {}
	}
}	

public boolean waitForImage(Image image, Component c, int id) {
	MediaTracker tracker = new MediaTracker(c);
	tracker.addImage(image, id);
	try {
  		tracker.waitForAll();
	}
	catch (InterruptedException ie) {}
	return (!tracker.isErrorAny());
}	

public int getSen(double ang, int d){
	return (int) (d * Math.sin(Math.toRadians(ang)));
}
 
public int getCos(double ang, int d){
	return (int) (d * Math.cos(Math.toRadians(ang)));
}	

public static void main(String args[]){
	teste t = new teste();		
	t.show();	
}	

}


Já resolvido…