Я работаю над Java-апплетом и просто для получения бонусных баллов, я хотел посмотреть, смогу ли я оживить траекторию того, что я сделал.У меня есть функция draw()
, чтобы анимировать, как я хотел, но анимация действительно быстрая, и вы едва можете ее увидеть.Я пытался увеличить миллисекунды в поточном процессе, но это не имело никакого значения.Надеюсь, мой вопрос имеет смысл.Я включил свой код ниже.
public class Slinkey extends Applet implements Runnable {
private static final long serialVersionUID = 4803949557086825455L;
private Thread animation;
private boolean stopSlinky;
@Override
public void start() {
stopSlinky = false;
animation = new Thread(this);
animation.start();
}
public void paint(Graphics g) { // This can probably be ignored.
Graphics2D g2 = (Graphics2D) g;
int x = 10;
int y = 10;
int w = 100;
int h = 100;
int k = 0;
int otherX = 0;
double xpos = 0, ypos = 10;
System.out.println(xpos + " " + ypos);
Ellipse2D.Double c1 = new Ellipse2D.Double(ypos, ypos, w, h);
for (k = 0; k < 155; k += 5) {
xpos = x + k;
ypos = getYStart(xpos);
System.out.println(xpos + " " + ypos);
c1.setFrame(xpos, ypos, w, h); // (10, 10) (1325, 650)
g2.draw(c1);
}
for (int i = 160; i < 775; i++) {
xpos = x + i;
otherX++;
ypos = getYMain(otherX);
if (ypos < 652) {
System.out.println("Y Coordinate: " + xpos + " " + ypos);
c1.setFrame(xpos, ypos, w, h);
g2.draw(c1);
}
}
for (int j = 775; j < 1325; j++) {
xpos = x + j;
otherX++;
ypos = (0.7) * (getYMain(otherX - 500) + 400);
if (ypos < 652) {
System.out.println("Y Coordinate: " + xpos + " " + ypos);
c1.setFrame(xpos, ypos, w, h);
g2.draw(c1);
}
}
}
public static double getYStart(double x) {
return (0.029) * (Math.pow(x - 10, 2) + 10);
}
public static double getYMain(double x) {
return ((0.005) * Math.pow(x - 350, 2) + 300);
}
@Override
public void run() {
while (true) {
if (stopSlinky) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public void stop() {
stopSlinky = true;
animation = null;
}
}
(я знаю, что код очень грязный. Я работаю над его организацией.)