excuse me,
im doing atomix game and there is something that i can do as an extra thing which is while the atom moves i see it moving no just disappearing and showing in the next position?
thx :)

Keep a separate thread or timer that updates the state of your objects and calls repaint() on the AWT event queue to refresh them.

This is referred to as a game loop or animation loop.

while (board[currentI - 1][currentJ].equals(".")) {
                board[currentI - 1][currentJ] = board[currentI][currentJ];
                board[currentI][currentJ] = ".";


this is part of moving code!

sry but how can i update in one thread:)?

Did you look at the post that I linked?

well yes but i didnt understand things in it :S :(

Perhaps this small example of animating the movement of a board piece with a thread might help. The important concept is in the BoardGrid.move() method, which is called when you press the button.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;

public class AnimateDemo extends JFrame{

    JButton btnMove = new JButton("Move");
    BoardGrid board = new BoardGrid();

    public AnimateDemo(){
        add(btnMove, BorderLayout.NORTH);
        add(board, BorderLayout.CENTER);

        btnMove.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

    class BoardGrid extends JComponent{
        Ellipse2D player = new Ellipse2D.Float(0, 0, 0, 0);
        int width=0;
        int height=0;

        // this method is just here to simplify the example
        // your player position update code could be anywhere
        public void move(){
            // create a thread to move the player
            Thread moveIt = new Thread(new Runnable() {
                public void run() {
                    for (int i=0; i<3; i++){
                        // update position
                        player.setFrame(i*width/3, height/3, width/3, height/3);
                        // repaint
                        // pause before next update
                        try {
                        } catch (InterruptedException ex) {

        protected void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;


            // draw board
            for (int i=1; i<3; i++){
                g2.drawLine(i*width/3, 0, i*width/3, height);
                g2.drawLine(0, i*height/3, width, i*height/3);

            // draw player
            if (player.getBounds().getWidth()>0){


    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                AnimateDemo demo = new AnimateDemo();
                demo.setSize(300, 300);