帮忙看一下这个程序
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class TimerMIDLet extends MIDlet {
Display display;
Snow snow=new Snow();
SnowMover mover=new SnowMover();
Time timer=new Timer();
public TimeMIDlet(){
display=Display.getDisplay(this);
}
protected void destroyedApp(boolean unconditional())
{ }
protected void startApp(){
display.setCurrent(snow);
timer.schedule(mover,100,100);
}
protected void pauseApp(){}
public void exit(){
time.cancel();
destroyApp(true);
notifyDestroyed();
}
}
class SnowMover extends TimerTask{
public void run(){
snow.scroll();
}
}
class Snow extends Canvas{
int height;
int width;
int[] snows;
Random generator=new Random();
boolean painting=false;
public Snow(){
height=getHeight();
width=getWidth();
snows=new int[height];
for(int i=0;i <height;i++){
snows[i]=-1;
}
}
public void scroll(){
if(painting)return;
for(int i=height-1;i> 0;--i){
snows[i]=snows[i-1];
}
snows[0]=(generator.nextInt()%(3*width))/2;
if(snows[0]> =width){
snows[0]=-1;
}
repaint();
}
protected void paint(Graphics g)
{painting=true;
g.setColor(180,180,180);
g.fillRect(0,0,width,height);
g.setColor(255,255,255);
for(int y=0;y <height;++y){
int x=snows[y];
if(x==-1)continue;
g.drawLine(x,y,x+2,y+2);
painting=false;
}
protected void keypressed(int keycode){
exit();
}
}
}
------解决方案--------------------看了...楼主素高人,这样的代码能编译吗?!
------解决方案--------------------错误百出
类名和构造方法名不一致,方法参数格式写错,接口方法名错误,括号位置错误
建议lz用IDE来开发
附修改过的代码:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class TimerMIDLet extends MIDlet {
Display display;
Snow snow = new Snow();
SnowMover mover = new SnowMover();