Application class
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class Application extends JFrame {
public Circle c1,c2,c3;
public Application() {
c1 =new Circle(100,100,2,2,new int[] {100,100,150,150},Color.blue);
c2 =new Circle(150,150,-2,0,new int[] {50,150,150,150},Color.red);
c3 =new Circle(50,150,2,-2,new int[] {100,10,150,150},Color.green);
setSize(1000,1000);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(c1.getColor());
g.fillOval(c1.getX(), c1.getY(), 10, 10);
g.setColor(c2.getColor());
g.fillOval(c2.getX(), c2.getY(), 10, 10);
g.setColor(c3.getColor());
g.fillOval(c3.getX(), c3.getY(), 10, 10);
}
public static void main(String[] args) {
Application a = new Application();
new Application();
}
}
Circle Class
import java.awt.Color;
public class Circle extends Thread {
private int x,y;
private int xs,ys;
private Color color;
private int[] boundries;
public Circle(int x ,int y ,int xs,int ys,int[]boundries,Color color) {
this.x=x;
this.y=y;
this.xs=xs;
this.ys=ys;
this.boundries=boundries; //kordinatlar ve buyukluk
this.color=color;
}
@Override
public void run() {
while(true) {
move();
}
}
public void move() {
UpdateSpeedInformation();
this.x +=this.xs; //xs artış kordinat hızı
this.y +=this.ys;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void UpdateSpeedInformation() {
if(x<boundries[0] && x>boundries[2]) { //eger x 0.indexten kücük 2.indexten büyükse
this.xs *= -1;
this.ys *= -1;
//kontrol operatörü bu
}
else if(y<boundries[1] && y>boundries[3]) {
this.xs=xs;
this.ys=ys; //..
}
}
public int getX() {
return x ;
}
public Color getColor() {
return color;
}
public int getY() {
return y;
}
}
These are the classes this three circle have to move but I dont know where I should place to Thread starters ask me if you need more information thanks
These are the classes this three circle have to move but I dont know where I should place to Thread starters ask me if you need more information thanks
These are the classes this three circle have to move but I dont know where I should place to Thread starters ask me if you need more information thanks