Problem with Repaint()
Hi, I am reletively new to Java programming. I am trying too make a game with a few people, and we have a minor problem. When I run this java applet, I get a horrible white line in our images when I repaint. I know there has to be a way to fix this, because it makes it look so choppy. Is there any way that you could tell me what I need to do? I would appreciate that so much.
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class Picture extends Applet implements KeyListener
{
private Image sonic[] = new Image[22];
private int X = 0, Y = 300; /* Initializing the variables for the X, and Y coordinates
of the images*/
int i = 0;
int s = 1;
int t = 2;
int facing = 0; // 0 is facing right, and 1 is facing left.
public void init()
{
sonic[0] = getImage(getDocumentBase(), "Sonic_Static_Right.gif");
sonic[1] = getImage(getDocumentBase(), "Sonic_Static_Left.gif");
sonic[2] = getImage(getDocumentBase(), "Sonic_Run_Right_1.gif");
sonic[3] = getImage(getDocumentBase(), "Sonic_Run_Right_2.gif");
sonic[4] = getImage(getDocumentBase(), "Sonic_Run_Right_3.gif");
sonic[5] = getImage(getDocumentBase(), "Sonic_Run_Right_4.gif");
sonic[6] = getImage(getDocumentBase(), "Sonic_Run_Right_5.gif");
sonic[7] = getImage(getDocumentBase(), "Sonic_Run_Right_6.gif");
sonic[8] = getImage(getDocumentBase(), "Sonic_Run_Right_7.gif");
sonic[9] = getImage(getDocumentBase(), "Sonic_Run_Right_8.gif");
sonic[10] = getImage(getDocumentBase(), "Sonic_Run_Left_1.gif");
sonic[11] = getImage(getDocumentBase(), "Sonic_Run_Left_2.gif");
sonic[12] = getImage(getDocumentBase(), "Sonic_Run_Left_3.gif");
sonic[13] = getImage(getDocumentBase(), "Sonic_Run_Left_4.gif");
sonic[14] = getImage(getDocumentBase(), "Sonic_Run_Left_5.gif");
sonic[15] = getImage(getDocumentBase(), "Sonic_Run_Left_6.gif");
sonic[16] = getImage(getDocumentBase(), "Sonic_Run_Left_7.gif");
sonic[17] = getImage(getDocumentBase(), "Sonic_Run_Left_8.gif");
sonic[18] = getImage(getDocumentBase(), "Sonic_Right_Duck.gif");
sonic[19] = getImage(getDocumentBase(), "Sonic_Left_Duck.gif");
sonic[20] = getImage(getDocumentBase(), "Sonic_Right_Look.gif");
sonic[21] = getImage(getDocumentBase(), "Sonic_Left_Look.gif");
addKeyListener(this);
requestFocus();
}
public void keyTyped(KeyEvent e)
{
}
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_LEFT)
{
X = X - 5;
if(s == 1)
{
i = 10;
i++;
repaint();
}
if(t % 2 == 0)
{
if(i == 17)
{
i = 10;
}
s++;
i++;
}
t++;
}
if(e.getKeyCode() == KeyEvent.VK_RIGHT)
{
X = X + 5;
if(s == 1)
{
i = 2;
i++;
repaint();
}
if(t % 2 == 0)
{
if(i == 9)
{
i = 2;
}
s++;
i++;
}
t++;
}
if(e.getKeyCode() == KeyEvent.VK_DOWN)
{
if (facing == 0)
i = 18;
if (facing == 1)
i = 19;
}
if(e.getKeyCode() == KeyEvent.VK_UP)
{
if (facing == 0)
i = 20;
if (facing == 1)
i = 21;
}
repaint();
}
public void keyReleased(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_RIGHT)
{
i = 0;
t = 2;
s = 1;
facing = 0;
repaint();
}
if(e.getKeyCode() == KeyEvent.VK_LEFT)
{
i = 1;
t = 2;
s = 1;
facing = 1;
repaint();
}
if(e.getKeyCode() == KeyEvent.VK_UP)
{
if (facing == 0)
i = 0;
if (facing == 1)
i = 1;
repaint();
}
if(e.getKeyCode() == KeyEvent.VK_DOWN)
{
if (facing == 0)
i = 0;
if (facing == 1)
i = 1;
repaint();
}
}
public void paint(Graphics g)
{
g.drawImage(sonic, X, Y, 40, 50, this);
}
}

