Java_Swing实现小球沿正弦曲线运动的代码

Java_Swing实现小球沿正弦曲线运动的代码
1 package zuidaimapack_1;
import java.awt.*;
import javax.swing.*;
/**
*Java_Swing实现小球沿正弦曲线运动的代码
* @author Visec·Dana
*/
public class SinRun extends JFrame implements Runnable {
private static final long serialVersionUID = 1L;
static int i = 0;
static int j = 250;
static double x = 0;
static double v = 5;// 速度
static double w = 2 * Math.PI;
static double A = 50;// 振幅
static double t = 0;// 时间 public SinRun() {
this.setSize(500, 500);
this.setVisible(true);
} public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.black);
g.fillOval(i, j + (int) x, 10, 10);
}
public void run() {
while (true) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// e.printStackTrace();
}
i += v;
x = A * Math.sin(w * t);
t += 0.1;
this.repaint();
if (i > 500)
i = 0;
}
}
public static void main(String args[]) {
new Thread(new SinRun()).start();
}
}
上一篇:webdriver杀死浏览器和Chromedriver进程


下一篇:1.通过模板创建MAP版本项目