java小球抛物线运动,当小球到底端时,重新进行此平抛运动。。。。。。。。。。。。。。。。。。。。
1个回答
展开全部
可以这样写:
import javax.swing.*;
import java.awt.*;
class C extends JFrame {
C() {
final Point point = new Point();
add(new JPanel() {
public void paintComponent(Graphics g) {
g.fillOval(point.x, point.y, 20, 20);
point.x = (point.x + 2) % getWidth();
point.y = (point.x * point.x) / 1000; // 造就弧线的简单二次方程。
}
});
setSize(777, 666);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
while (true) {
repaint(point.x, point.y, 50, 50);
try { Thread.sleep(10); } catch (Exception ex) {}
}
}
public static void main(String[] args) {
new C();
}
}
import javax.swing.*;
import java.awt.*;
class C extends JFrame {
C() {
final Point point = new Point();
add(new JPanel() {
public void paintComponent(Graphics g) {
g.fillOval(point.x, point.y, 20, 20);
point.x = (point.x + 2) % getWidth();
point.y = (point.x * point.x) / 1000; // 造就弧线的简单二次方程。
}
});
setSize(777, 666);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
while (true) {
repaint(point.x, point.y, 50, 50);
try { Thread.sleep(10); } catch (Exception ex) {}
}
}
public static void main(String[] args) {
new C();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询