package eclipse1;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class balltest extends MIDlet implements CommandListener {
public static int stop=0;
private Display dis;
private MyCanvas mc=new MyCanvas();
private time tm=new time();
private Timer tis=new Timer();
public balltest() {
// TODO 自动生成的构造函数存根
}
protected void startApp() throws MIDletStateChangeException {
// TODO 自动生成的方法存根
dis=Display.getDisplay(this);
dis.setCurrent(mc);
//mc.setFullScreenMode(true);
mc.addCommand(new Command("停止",Command.BACK,1));
mc.addCommand(new Command("继续",Command.OK,1));
mc.setCommandListener(this);
tis.schedule(tm, new Date(), 1000);
}
public void commandAction(Command c,Displayable d)
{
if(c.getLabel().equals("停止"))
{
stop=1;
}
else if(c.getLabel().equals("继续"))
{
stop=2;
}
}
{
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO 自动生成的方法存根
}
protected void pauseApp() {
// TODO 自动生成的方法存根
}
class time extends TimerTask
{
public void run() {
// TODO 自动生成的方法存根
while(true)
{
if(mc.y>=mc.getHeight()-20|stop==1)
{
break;
}
mc.y++;
mc.repaint();
try
{
Thread.currentThread().sleep(20);
}
catch(Exception e)
{
}
}
}
}
class MyCanvas extends Canvas
{
private int y;
public void paint(Graphics g)
{
g.setColor(255,255,255);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(255,0,0);
g.fillArc(this.getWidth()/2-20, y, 20,20, 0, 360);
}
}
}
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class balltest extends MIDlet implements CommandListener {
public static int stop=0;
private Display dis;
private MyCanvas mc=new MyCanvas();
private time tm=new time();
private Timer tis=new Timer();
public balltest() {
// TODO 自动生成的构造函数存根
}
protected void startApp() throws MIDletStateChangeException {
// TODO 自动生成的方法存根
dis=Display.getDisplay(this);
dis.setCurrent(mc);
//mc.setFullScreenMode(true);
mc.addCommand(new Command("停止",Command.BACK,1));
mc.addCommand(new Command("继续",Command.OK,1));
mc.setCommandListener(this);
tis.schedule(tm, new Date(), 1000);
}
public void commandAction(Command c,Displayable d)
{
if(c.getLabel().equals("停止"))
{
stop=1;
}
else if(c.getLabel().equals("继续"))
{
stop=2;
}
}
{
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO 自动生成的方法存根
}
protected void pauseApp() {
// TODO 自动生成的方法存根
}
class time extends TimerTask
{
public void run() {
// TODO 自动生成的方法存根
while(true)
{
if(mc.y>=mc.getHeight()-20|stop==1)
{
break;
}
mc.y++;
mc.repaint();
try
{
Thread.currentThread().sleep(20);
}
catch(Exception e)
{
}
}
}
}
class MyCanvas extends Canvas
{
private int y;
public void paint(Graphics g)
{
g.setColor(255,255,255);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(255,0,0);
g.fillArc(this.getWidth()/2-20, y, 20,20, 0, 360);
}
}
}