How do you use a timer to move images and how do you create a loop for your timer?
<p>I am trying to make a mini game where images move in from all four corners and try to attack you. But I can't seem to make the images start advancing towards the middle. My code usually prints one picture then does nothing after that. I want to make the images move towards the center but I can't figure out how to loop my timer to make that work. I'm not very good at explaining so  i'll put all of my code here.</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Game extends JPanel  {
private static  int PREF_W = 700;
private static  int PREF_H = PREF_W;
public int count = 0;
private int randCount = (int)(Math.random()*3000 + 10000);
private int randCount1 = (int)(Math.random()*100 + 50);
private int count1,count2,count3 = 0;
boolean x = true;
private static Timer t;

public Game() {
  setFocusable(true);
  requestFocusInWindow();

  addKeyListener(new KeyAdapter() {

     @Override
     public void keyTyped(KeyEvent e) {
        myKeyEvt(e, "keyTyped");
     }

     @Override
     public void keyReleased(KeyEvent e) {
        myKeyEvt(e, "keyReleased");
     }

     @Override
     public void keyPressed(KeyEvent e) {
        myKeyEvt(e, "keyPressed");
     }

     private void myKeyEvt(KeyEvent e, String text) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_KP_UP || key == KeyEvent.VK_UP)
        {
            count = 1;

            repaint();
            //Call some function
        }
        if (key == KeyEvent.VK_KP_LEFT || key == KeyEvent.VK_LEFT)
        {
            count =2;

            repaint();
            //Call some function
        }
        if (key == KeyEvent.VK_KP_DOWN || key == KeyEvent.VK_DOWN)
        {
            count = 3;

            repaint();
            //Call some function
        }

        else if (key == KeyEvent.VK_KP_RIGHT || key == KeyEvent.VK_RIGHT)
        {
            count = 4;

            repaint();
            //Call some function
        }

     }

  });

   t = new Timer(randCount, new ActionListener(){

       @Override
       public void actionPerformed(ActionEvent evt){
           if(count1 == 0)
           {
               PREF_H = ((PREF_H/15)+randCount1);
               count2 = 5;
               System.out.print("dasfasfdsadf");
               repaint(count2);
               count1 += 1;
               t = new Timer(randCount1,this);
               if(PREF_H &gt; (PREF_H/2))
               { 
                   t.stop();
               }

           }
           else if(count1 == 1)
           {
               count2 = 10;

               System.out.print("dasfasfdsadf");
               repaint(count2);
               count1 = 2;
               t = new Timer(randCount1,this);
               count1 = 2;
               if(PREF_W &gt; (PREF_W/2))
               { 
                   t.stop();
               }
           }
           else if(count1 == 2)
           {
               count2 = 15;

               System.out.print("dasfasfdsadf");
               repaint(count2);
               count1 = 3;
               t = new Timer(randCount1,this);
               count1 = 3;
               if(PREF_H &gt; (PREF_H/2))
               { 
                   t.stop();
               }
           }
           else if(count1 == 3)
           {
               count2 = 20;

               System.out.print("dasfasfdsadf");
               repaint(count2);
               count1 = 0;
               t = new Timer(randCount1,this);
               count1 = 0;
               if(PREF_W &gt; (PREF_W/2))
               { 
                   t.stop();
               }
           }

       }
   });

      Game.start();      

  }

    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

public static void start()
{

t.start();
System.out.print("ssssssssssssss");

  }

   public void paintComponent(Graphics g)
             { 
                 Image StartScreenImage =      Toolkit.getDefaultToolkit().getImage("GameField.jpg");
                   g.drawImage(StartScreenImage,0,0,PREF_W,PREF_H,0,0,900,504,this);

                 Color pokemonGreen = new Color(185,235,160);
                 setBackground(pokemonGreen);

                 if(count==3)
                 {
                  Image Player = Toolkit.getDefaultToolkit().getImage("Player.jpg");
                 g.drawImage(Player,(PREF_W/2),(PREF_H/2),((PREF_W/2)+46),((PREF_H/2)+40),0,0,46,40,this);


                 }
                 if(count == 2)
                 {
                     Image Player2 = Toolkit.getDefaultToolkit().getImage("Player2.jpg");
                 g.drawImage(Player2,(PREF_W/2),(PREF_H/2),((PREF_W/2)+46),((PREF_H/2)+40),0,0,46,40,this); 

                 }
                 if(count == 4)
                 {
                     Image Player4 = Toolkit.getDefaultToolkit().getImage("Player4.jpg");
                 g.drawImage(Player4,(PREF_W/2),(PREF_H/2),((PREF_W/2)+46),((PREF_H/2)+40),0,0,46,40,this);    
                 }
                 if(count == 1)
                 {
                     Image Player3 = Toolkit.getDefaultToolkit().getImage("Player3.jpg");
                 g.drawImage(Player3,(PREF_W/2),(PREF_H/2),((PREF_W/2)+46),((PREF_H/2)+40),0,0,46,40,this);    
                 }
                 if(count2 == 5)
                 {
                      Image Zubat = Toolkit.getDefaultToolkit().getImage("Zubat.jpg");
                 g.drawImage(Zubat,((PREF_W/2)-27),(PREF_H),this);
                  System.out.print("11111111");
                  count1 += 1;
                  t.stop();
                  start();
                 }
                 if(count2 == 10)
                 {
                      Image Zubat4 = Toolkit.getDefaultToolkit().getImage("Zubat4.jpg");
                 g.drawImage(Zubat4,((PREF_W/15)+randCount1),((PREF_H/2)),this);
                  System.out.print("22222222222222");
                  count1 += 1;
                  t.stop();
                  start();

                 }
                 if(count2 == 15)
                 {
                      Image Zubat3 = Toolkit.getDefaultToolkit().getImage("Zubat3.jpg");
                 g.drawImage(Zubat3,((PREF_W/2)+randCount1),((PREF_H/15)),this);
                  System.out.print("3333333333333");
                  count1 += 1;
                  t.stop();
                  start();

                 }
                 if(count2 == 20)
                 {
                      Image Zubat2 = Toolkit.getDefaultToolkit().getImage("Zubat2.jpg");
                 g.drawImage(Zubat2,((PREF_W/15)-randCount1),((PREF_H/2)),this);
                  System.out.print("44444444444444");
                  count1=0;
                  t.stop();
                  start();

                 }

             }
     @Override
     public Dimension getPreferredSize() {
  return new Dimension(PREF_W, PREF_H);
      }

    private static void createAndShowGui() {
  Game mainPanel = new Game();

  JFrame frame = new JFrame("Dungeon Of Geometry");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().add(mainPanel);
  frame.pack();
  frame.setLocationByPlatform(true);
  frame.setVisible(true);

     }
    public static void main(String[] args) {
  SwingUtilities.invokeLater(new Runnable() {
     public void run() {
        createAndShowGui();
     }
  });
     }
   }
</code></pre>