📄 bouncingball.java
字号:
/*
* BouncingBall.java
* Andreas Jakl
*/
package Bounce;
import javax.microedition.lcdui.Graphics;
public class BouncingBall
{
private int maxWidth;
private int maxHeight;
private int xPos;
private int yPos;
private int xDir;
private int yDir;
private int radius;
/** Creates a new instance of BouncingBall */
public BouncingBall ()
{
}
public void init (final int aMaxWidth, final int aMaxHeight)
{
maxWidth = aMaxWidth;
maxHeight = aMaxHeight;
xPos = maxWidth / 2;
yPos = maxHeight / 2;
radius = 20;
xDir = 3;
yDir = 3;
}
public void paint (Graphics g)
{
g.setColor (255, 0, 0);
g.fillArc (xPos, yPos, radius, radius, 0, 360);
}
public void updatePosition()
{
xPos += xDir;
yPos += yDir;
if (xPos + radius >= maxWidth || xPos <= 0)
xDir = -xDir;
if (yPos + radius >= maxHeight || yPos <= 0)
yDir = -yDir;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -