Please...need help with 2D game in Java.

PLease.
Help me.
I have some problem with my Racing Game in Java.
My car is image, which I’m importing from same folder.
And this car is blinking very much. How to do it without blinking.

Below I put my source code:

package test;

import java.applet.;
import java.awt.
;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
public class qe extends Applet implements Runnable
{
private int x_speed=25;
private int y_speed=230;
private int ngr;
double cos, sin;
Image img;
Image track;
int ss=1;
BufferedImage bi;
boolean bl= false;
float grad;
public void init()
{
setBackground(Color.blue);
setSize(700, 430);
img=getToolkit().getImage(“test\3.gif”);
track=getToolkit().getImage(“test\race.jpg”);
try
{
MediaTracker ld=new MediaTracker(this);
ld.addImage(img,0);
ld.addImage(track, 0);
ld.waitForID(0);
}
catch(Exception e){}

	bi=new BufferedImage(60,140, BufferedImage.TYPE_INT_RGB);
	Graphics2D big=bi.createGraphics();
	big.drawImage(img,0,0,this);
}
public void start()
{
	Thread t=new Thread(this);
	t.start();
}
public void stop()
{
	
}
public void destroy()
{
	
}
public boolean keyDown(Event e, int key)
{
	ngr=(int) (grad*180/Math.PI);
	cos=Math.cos(ngr*Math.PI/180);
	sin=Math.sin(ngr*Math.PI/180);
	if(key==Event.UP)
	{
		if(ss<15)
		{
			ss +=15;
		}
		
	}
	else
		if(key==Event.DOWN)
		{
			if(ss>-15)
			{
				ss-=15;
			}
			
		}
	
		
		
	else 
		if(key==Event.LEFT)
		{
			if(ngr==-360 || ngr==360)
			{
				grad=0;
			}
			grad-=0.07;
			ngr=(int) (grad*180/Math.PI);
			System.out.println(ngr);
		}
	else
	if(key==Event.RIGHT)
	{
		if(ngr==-360 || ngr==360)
		{
			grad=0;
		}
		
		grad+=0.07;
		ngr=(int) (grad*180/Math.PI);
		System.out.println(ngr);

	}
	else
	if(key==32)
	{
		bl=true;
	}
	return true;
	
}
public void update(Graphics g)
{
	paint(g);
}
	
public void run() 
{
		while(true)
		{
			
			if(bl)
			{
				cos=Math.cos(ngr*Math.PI/180);
				sin=Math.sin(ngr*Math.PI/180);
				
				if(x_speed>600)
				{
					ss=-1;
				}
				else
					if(x_speed<0)
				{
					ss=-1;
				}
				else
					if(y_speed>400)
				{
				ss=-1;
				}
				else
					   if(y_speed<-50)
				{
				ss=-1;
				}
				 else
				  if(y_speed<-50)
				{
				ss=-1;
					}
				if(ngr==360 || ngr==0 || ngr==-360)
				{
				y_speed-=ss;
				}
				else
					if(ngr==88 ||  ngr==-268)
					{
						x_speed+=ss;
					}
					else
						if(ngr==268 || ngr==-90)
							
					{
						x_speed-=ss;
					}
						else
							if(ngr==180 || ngr==0)
							{
								y_speed+=ss;
							}
							else
				if(cos>0)//go Up
				{
					if(sin>0)// go right
					{
						y_speed-=ss;
						x_speed+=ss;
					}
					else
						if(sin<0)// go left
						{
							y_speed-=ss;
							x_speed-=ss;
						}
				}
				else
					if(cos<0)//go down
					{
						if(sin>0)// go right
						{
							x_speed+=ss;
							y_speed+=ss;
						}
						else
							if(sin<0)// go left
							{
								x_speed-=ss;
								y_speed+=ss;
							}
						
					}
			
			}
			try
			{
				Thread.sleep(250);
			}
			catch(InterruptedException e){}
			
			repaint();
		}
		
}

public void paint(Graphics g)
{
	
	//g.drawImage(img, x_speed,y_speed,this);
	g.drawImage(track,0,0,this);
	/*g.setColor(Color.red);
	g.fillRect(x_speed, y_speed, 50, 50);*/
	Graphics2D gr=(Graphics2D)g;
	AffineTransform at=new AffineTransform();
	
	at.setToRotation(grad,40,40);
	BufferedImage bimg=new BufferedImage(67,67, BufferedImage.TYPE_INT_RGB);
	BufferedImageOp biop=new AffineTransformOp(at,AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
	biop.filter(bi,bimg);
	
	gr.drawImage(bi,biop,x_speed,y_speed);
	
}

}

  • Use an offscreen buffer
  • Read java painting tutorials, there are a lot
  • Why do you use an BufferedImageOp? You do that on each paint, its expensive. I dont know what it does, but perhaps you only need it done once?
  • You can cast Graphics to Graphics2D, which allows using AffineTransform, so you probably dont need the Op.
  • Use better variable names than bi, bim, img, and so on. No one can easly read your code with such names. Additionally you seem to use x_speed and y_speed as coordinates for the drawimage, either the name of the var or its use is wrong.

With a little work, there are many examples in the web, you can solve this yourself.

-JAW