I got a code, where I used animation.
The program gets some information via bluetooth and converts it, then it should move a picture to certain points. And it should keep going until all information is read.

Now it receives all information, and image moves, but problem is that it make animation after all information have received. (i.e. it makes animation from start point and final point) But I need to make animation, which draws image immediately after receiving data. (step by step)

This is my code:


Code:
public class Basic extends TimingTargetAdapter implements ActionListener {
    
   public static final int RACE_TIME = 900;    
    static Point start = new Point(94, 558);
    static Point end = new Point(94, 558);
    static Point current = new Point();
    protected Animator animator;
    TrackView track;
    RaceControlPanel controlPanel;
    // more parameters

/** Creates a new instance of BasicRace */
    public Basic(String appName) {
        //Container container = getContentPane();
        RaceGUI basicGUI = new RaceGUI(appName);
        controlPanel = basicGUI.getControlPanel();
        controlPanel.addListener(this);
        track = basicGUI.getTrack();
        animator = new Animator(RACE_TIME, this);
    }

/**
     * This receives the Go/Stop events that start/stop the animation
     */
    public void actionPerformed(ActionEvent ae) {
    	if (ae.getActionCommand().equals("Connect"))
    		connect();

        if (ae.getActionCommand().equals("Start")) {

            start();
            
        } else if (ae.getActionCommand().equals("Stop")) {
        	System.exit(0);
      	  	disconnect();
        }
    }

 public static void connect() { ...}

public static void disconnect() { ... }

public void start(){
		  mazeInitial();
		  xi = 0;
		  yi = 7;
		  try {
			  outData.writeInt(1);
			  outData.flush();
			  while (true){
				  transmitReceivedDirection = inData.readInt();
				  transmitReceivedWall = inData.readInt();
				  //System.out.println(transmitReceivedWall + " <<<------------");
				  drawWall(transmitReceivedDirection, transmitReceivedWall, xi, yi);
				  animator.stop();
				  animator.start();

			  }
        } 
		  catch (IOException ioe) { System.out.println("\nIO Exception writeInt"); } 
	  }

public void mazeInitial() { ... }

// Here I change position of the points
public void dir(int number, int dir) {

		  switch (number) {
		  case 0: {  // R
			  switch (dir){
			  	case 0: { xi += 1; end.x += 70; break;}
			  	case 1: { yi += 1; end.y += 70; break;}
			  	case 2: { xi -= 1; end.x -= 70; break;}
			  	case 3: { yi -= 1; end.y -= 70; break;}
			  } break;
		  }
		  case 1: {  // R
			  switch (dir){
			  	case 0: { xi += 1; end.x += 70; break;}
			  	case 1: { yi += 1; end.y += 70; break;}
			  	case 2: { xi -= 1; end.x -= 70; break;}
			  	case 3: { yi -= 1; end.y -= 70; break;}
			  } break;
		  }
                  ....
       }

/**
     * TimingTarget implementation: calculate and set the current
     * car position based on the animation fraction
     */
    public void timingEvent(float fraction) {
    	
        // Simple linear interpolation to find current position
        current.x = (int)(start.x + (end.x - start.x) * fraction);
        current.y = (int)(start.y + (end.y - start.y) * fraction);
        
        // set the new position; this will force a repaint in TrackView
        // and will display the car in the new position
        track.setCarPosition(current);
      }

    public static void main(String args[]) {
        Runnable doCreateAndShowGUI = new Runnable() {
            public void run() {
                Basic race = new Basic("Race");
            }
        };
        SwingUtilities.invokeLater(doCreateAndShowGUI);
    }   
}


class RaceControlPanel extends JPanel { ... }

class RaceGUI {

    private TrackView track;
    private RaceControlPanel controlPanel;

    /**
     * Creates a new instance of RaceGUI
     */
    public RaceGUI(String appName) {
        ...
    }
    
    public TrackView getTrack() {
        return track;
    }
    
    public RaceControlPanel getControlPanel() {
        return controlPanel;
    }
}

class TrackView extends JComponent {
    
    BufferedImage car;
    BufferedImage track;
    Point carPosition;
    double carRotation = 0;
    int trackW, trackH;
    int carW, carH, carWHalf, carHHalf;

    /** Hard-coded positions of interest on the track */
    //static Point START_POS = new Point(94, 558);
    static Point START_POS = Basic.start;
    static Point END_POS = Basic.end;
    
    /** Creates a new instance of TrackView */
    public TrackView() {
        try {
            car = ImageIO.read(TrackView.class.getResource("qwe1.gif"));
            track = ImageIO.read(TrackView.class.getResource("track.jpg"));
        } catch (Exception e) {
            System.out.println("Problem loading track/car images: " + e);
        }
        carPosition = new Point(START_POS.x, START_POS.y);
        carW = car.getWidth();
        carH = car.getHeight();
        carWHalf = carW / 2;
        carHHalf = carH / 2;
        trackW = track.getWidth();
        trackH = track.getHeight();
    }
    
    public Dimension getPreferredSize() {
        return new Dimension(trackW, trackH);
    }
    
    /**
     * Render the track and car
     */
    public void paintComponent(Graphics g) {
        // First draw the race track
        g.drawImage(track, 0, 0, null);
        int x = 70, y = 530;
        
        // Now draw the car.  The translate/rotate/translate settings account
        // for any nonzero carRotation values
        Graphics2D g2d = (Graphics2D)g.create();
        g2d.translate(carPosition.x, carPosition.y);
        g2d.translate(-(carPosition.x), -(carPosition.y));
         
        // Now the graphics has been set up appropriately; draw the
        // car in position
        g2d.drawImage(car, carPosition.x - carWHalf, carPosition.y - carHHalf, null);
    }
    
    /**
     * Set the new position and schedule a repaint
     */
    public void setCarPosition(Point newPosition) {
        repaint(1, carPosition.x - carWHalf, carPosition.y - carHHalf, carW, carH);
        carPosition.x = newPosition.x;
        carPosition.y = newPosition.y;
        repaint(0, carPosition.x - carWHalf, carPosition.y - carHHalf, carW, carH);
    }
}
I tried to explain everything and paste almost whole code. (Maybe some unnecessary parts)
I know it's annoying to look to somebody's code, but if you have time, and can understand it, could you help me?

If have any question I'll explain it.

Thank you in advance.