java碰撞小球代码 js两个小球碰撞( 二 )


}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
setBackground(Color.BLACK);
g.setColor(color);
g.fillOval(x, y, 50, 50);
}
public void run() {
while (true) {
if (x = 0) {
dx = 5;
updateBallColor();
} else if ((x + 50) = getWidth()) {
dx = -5;
updateBallColor();
}
if (y = 0) {
dy = 5;
updateBallColor();
} else if ((y + 50) = getHeight()) {
dy = -5;
updateBallColor();
}
x = x + dx;
y = y + dy;
repaint();
try {
Thread.sleep(25);
} catch (InterruptedException e) {
;
}
}
}
public void updateBallColor() {
rgb = new Random().nextInt();
color = new Color(rgb);
}
}
java碰撞小球代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于js两个小球碰撞、java碰撞小球代码的信息别忘了在本站进行查找喔 。

推荐阅读