13,100
社区成员
发帖
与我相关
我的任务
分享
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.perseus.parser.ColorParser;
public class bool extends MIDlet {
Display dis;
Can ca;
public bool() {
dis=Display.getDisplay(this);
ca=new Can();
ca.setTitle("会滚动的小球");
dis.setCurrent(ca);
new Thread(ca).start();
}
protected void startApp() throws MIDletStateChangeException {
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO 自动生成方法存根
}
protected void pauseApp() {
// TODO 自动生成方法存根
}
class Can extends Canvas implements Runnable
{
int x=0,y=0;
int Width=this.getWidth();
int Heigth=this.getHeight();
int dx=8,dy=8;
final int r=7;
Can()
{
//setFullScreenMode(true);
}
void move()
{
x=x+dx;
y=y+dy;
if(x+r>=Width)
{
x=Width-r;
dx=-dx;
}
if(x-r<0)
{
x=0;
dx=-dx;
}
if(y+r>=Heigth)
{
y=Heigth-r;
dy=-dy;
}
if(y-r<0)
{
y=0;
dy=-dy;
}
}
protected void paint(Graphics g) {
g.setColor(250,250,250);
g.fillRect(0, 0, Width, Heigth);
move();
g.setColor(100,255,20);
g.fillRoundRect(x, y, r,r,90,90);
}
public void run() {
while(true)
{
repaint();
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
}
}