不懂,出错了!

linuxgyh 2004-08-23 11:13:49
src中有两个文件:

一个是:
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class MyGameCanvas extends GameCanvas
implements Runnable
{
public MyGameCanvas()
{
super(true);
}
boolean conti=true;
int rate=50;
public void run()
{
long st=0;
long et=0;
Graphics g=getGrapics();
while(conti)
{
st=System.currentTimeMillis();
render(g);
et=System.currentTimeMillis();
if((et-st)<rate)
{
try{
Thread.sleep(tate-(et-st));
}catch(Exception exp){}


}
}
}
int x=50;
int y=10;
public void render(Graphics g)
{
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(0,0,0);
g.drawString("Test",x,y,0);
x++;
if(x>getWidth())
{
x=0;
flushGraphics();

}
public void start()
{
Thread t=new Thread(this);
t.start();

}
public void exit()
{
conti=false;

}
public void keyPressed(int keycode)
{
System.out.println("bit event");

}

}

}



另外一个是:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class GameMIDlet extends MIDlet
implements CommandListener
{
Display display;
public GameMIDlet();
{
display=Display.getDisplay(this);
}
MyGameCanvas mgc;
public void startApp()
{
if(mgc==null)
{
mgc=new MyGameCanvas();
mgc.addCommand(new Command("start",Command.OK,1));
mgc.addCommand(new Command("end",Command.EXIT,2));
mgc.setCommandListener(this);
display.setCurrent(mgc);
}

}
public void commandAction(Command c,Display s)
{
String cmd=c.getLabel();
if(cmd.equals("start"))
{
mgc.start();

}else if(cmd.equals("end"))
{
mgc.exit();
notifyDestroyed();

}

}
public void pauseApp()
{}
public void destroyApp(boolean unconditional)
{}
}


出错提示是:

Project settings saved

Building "klion"

C:\WTK20\apps\klion\src\MyGameCanvas.java:47: illegal start of expression

public void start()

^

C:\WTK20\apps\klion\src\MyGameCanvas.java:63: ';' expected



^

2 errors

com.sun.kvem.ktools.ExecutionException

Build failed

但是我找不到错呀!高手请指教!


...全文
46 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
minj2me 2004-08-23
public void start()
{
Thread t=new Thread(this);
t.start();

}
public void exit()
{
conti=false;

}
public void keyPressed(int keycode)
{
System.out.println("bit event");

}
a.这些方法不应试放在render(Graphics g)方法里面
b.public GameMIDlet()后多了分号
c.public void commandAction(Command c,Displayable s)
回复
lumber 2004-08-23
在 if(x>getWidth())下面多了一个"{"


回复
相关推荐
发帖
J2ME
创建于2007-09-28

1.3w+

社区成员

Java J2ME
申请成为版主
帖子事件
创建了帖子
2004-08-23 11:13
社区公告
暂无公告