synchronized circles java

import javax.swing.JFrame;

public class MAIN1 {

public static void main(String[] args) 
{
	Display b=new Display();	
	JFrame j=new JFrame();
	j.setSize(700, 700);
	j.add(b);
    j.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	j.setVisible(true);
}

}

public class loc
{
public int x;
public int y;
public int radius;
public loc(int x,int y,int r)
{
this.x=x;
this.y=y;
this.radius=r;
}
public int getX() {
return this.x;
}
public void setX(int x) {
this.x =x;
}
public int getY() {
return this.y;
}
public void setY(int y) {
this.y =y;
}
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}

}

import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

import javax.swing.JPanel;

public class Display extends JPanel
{
public loc [] ar=new loc[5];
private int dx=1;
private int dy=1;
public Display()
{
for(int i=0; i<5; i++)
this.ar[i]=new loc(new Random().nextInt(615)+25,new Random().nextInt(615)+25,new Random().nextInt(30)+25);
}

public void paintComponent(Graphics g)
{	
	g.setColor(Color.darkGray);                    // clear the frame ...
	g.fillRect(0, 0, getWidth(), getHeight());			
	g.setColor(Color.red);
	for(int i=0; i<ar.length; i++)
	g.fillOval(ar[i].x, ar[i].y, ar[i].radius,ar[i].radius);
	update();

}


public void update()
{
	try {
		Thread.sleep(5);
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	check();
	repaint();
}

 public void check()
 {
	 for(int i=0; i<ar.length; i++)
	 {

    	if(ar[i].x<0)
    		dx=1;
    	if(ar[i].x>=this.getWidth()-45)
    		dx=-1;
    	if(ar[i].y<0)
    		dy=1;
    	if(ar[i].y>=this.getHeight()-45)
    		dy=-1;
    	ar[i].x+=dx;
    	ar[i].y+=dy;
    }

 }

}

Sorry about lower letters in name’s classes.
my problem is thaht the circles is synchronized ,they move by one circle.
i want they will not be synchronized … what i should change in the code?
Thank you.

So you want each circle to move in its own direction? Move ‘dx’ and ‘dy’ to inside class ‘loc’ and generate ‘dx’ and ‘dy’ randomly too. In check(), you reference ‘ar[i].dx’ and ‘ar[i].dy’ instead.