I need to let an image fly in a cirle, i'm now only stuck on one part. For calculating the points it needs to go im using pythagoras to calculate the height (point B).
Now when using the sqrt function I the the error that I can't convert a double to an int. Here's my code :
package vogel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
public class vogel extends Component {
private int x;
private int r;
private int b;
BufferedImage img;
public vogel() {
try {
img = ImageIO.read(new File("F:/JAVA/workspace/School/src/vogel/vogel.png"));
} catch (IOException e) {
}
r = 6;
}
@Override
public void paint(Graphics g) {
for(int i = -r; i <= r; i++) {
x = i;
b = Math.sqrt(r^2 - x^2);
g.drawImage(img, x, b, this);
}
}
public static void main(String[] args) {
JFrame f = new JFrame("Boot");
f.setSize(1000,1000);
f.add(new vogel());
f.setVisible(true);
for (int number = 1; number <= 1500000; number++) {
f.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {}
}
}
}
Hope one of you guys can help me out