   [java] help: weird graphics problem
  Hi every one,I've made a little program to test graphics and keyboard input. It worked, but the thing is when I hit space (for the sword attack) the program responds real slow, and some frames don't show up. When I ran the program with the server VM, there was no problem so i think that the problem is with my code. Here it is:import java.awt.event.*;import java.awt.Graphics;import java.awt.Image;import javax.swing.JApplet;import javax.swing.JFrame;class animation extends JApplet implements Runnable,   KeyListener{    static Thread t;    Graphics offscr;    Image offscreenimage;    boolean atck=false;    Image soldier;    int iterator=1;    int deslocatorX=0;    int deslocatorY=0;    public animation(){}    public Image loadImage(int i)    {    soldier = getToolkit().getImage("anim\\BahamutLagoon_EmpireSoldier"+i+".gif");    return soldier;    }    public void graphicBuffer(Graphics screen)    {    offscreenimage=createImage(400,100);    offscr = offscreenimage.getGraphics();    offscr.clearRect(0,0,400,100);    offscr.drawImage(loadImage(iterator), deslocatorX,deslocatorY, this);    screen.drawImage(offscreenimage,0,0,this);    }    public void paint(Graphics g)    {    graphicBuffer(g);  }    public void run() {  while(true)  {   repaint();   if(atck){   iterator++;}   if(iterator==13) {iterator=1; atck=false;}   try{  t.sleep(1000/30); } catch (InterruptedException e) {break; }  } } public void keyTyped(KeyEvent e) {    }   public void keyPressed(KeyEvent e) {   switch(e.getKeyCode())   {case 32: atck=true;break;    case 37: deslocatorX--;break;    case 38: deslocatorY--;break;    case 39: deslocatorX++;break;    case 40: deslocatorY++;break;    default: break;   }}   public void keyReleased(KeyEvent e) {   }public static void main(String[] args){    JFrame f = new JFrame("Soldier");    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    animation anim = new animation();    f.add(anim);    f.addKeyListener(anim);    f.setSize(400, 100);    f.setVisible(true);    f.requestFocus();    t=new Thread(anim);  t.start();  }}The sprite's gifs are here: www.angelfire.com/weird2/gghp/anim.zip.So I wanted to ask you guys if there's any way to make this run faster. I'm asking in this forum because I think it is a language-related problem. Any advice that you feel that could be useful please tell me. It's my first post here and English is not my first language so forgive me if my explanation was a bit fuzzy.Thanx[Edited by - Dark Lord Hertious on December 16, 2005 8:48:11 PM]
  You're calling loadImage() in your paint() method, try preloading all of your images into an array at the beginning of run(). Hope that helps. Nice sprites, by the way.P.S. Please use source tags.   ;Thanks! Instead of using the LoadImage I loaded all the images in an array like you said, but inside the constructor, wich I think is the same as putting it in the begining of  the run() method. It worked very well.As for the sprites, I don't remember wich site I took them, but I'm pretty sure that it is in the sprite resource thread.I edited the last post, looks much better know.   