报screen exception:java.lang installexception:class not a midlet异常 原码如下:
import javax.microedition.lcdui.*;
//import javax.microedition.midlet.*;
public class screen extends Canvas implements Runnable , CommandListener
{
Command start=new Command("start",Command.OK,1);
Command stop=new Command("stop",Command.STOP,1);
private Image offscreen;
public screen() {
addCommand(start);
addCommand(stop);
if (isDoubleBuffered())
{
System.out.println("mutable");
}
else
{ System.out.println("immutable");
offscreen=Image.createImage(getWidth(),getHeight());
}// TODO Auto-generated constructor stub
}
public void paint(Graphics g){
if(isDoubleBuffered())
{
System.out.println("on-screen");
clear(g);
paintAnimation(g,100,10,r);
paintCross(g,x,y,length);
}
else
{
System.out.println("off-screen");
Graphics offs=offscreen.getGraphics();
clear(offs);
paintAnimation(offs,100,10,r);
paintCross(offs,x,y,length);
g.drawImage(offscreen,0,0,0);
}
}
public void clear(Graphics g){
g.setColor(255,255,55);
g.fillRect(0,0,getWidth(),getHeight());
}
int r=0;
public void paintAnimation(Graphics g,int x,int y,int l){
g.setColor(255,255,0);
g.drawLine(x-length,y,x+length,y);
g.drawLine(x,y-length,x,y+length);
}
boolean conti=false;
int x=50;
int y=50;
int length=5;
public void paintCross(Graphics g,int x,int y ,int length){
g.setColor(255,0,0);
g.drawLine(x-length,y,x+length,y);
g.drawLine(x,y-length,x,y+length);
}
public void commandAction(Command c,Displayable s){
String cmd=c.getLabel();
if(cmd.equals("stop"))
{
conti=false;
removeCommand(stop);
addCommand(start);
}
else if(cmd.equals("start"))
{
removeCommand(start);
addCommand(stop);
conti=true;
Thread t=new Thread(this);
t.start();
}
}
int rate=50;
public void run(){
long s=0;
long e=0;
long diff=0;
while(conti){
s=System.currentTimeMillis();
r++;
if(r>10)
r=0;
repaint();
serviceRepaints();
e=System.currentTimeMillis();
diff=e-s;
if(diff<rate)
try{
Thread.sleep(rate-diff);
}catch(Exception exc){}