import java.io.*; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; public class canvas extends GameCanvas implements Runnable{ public LayerManager manager; public TiledLayer fon; public Thread t; public Image img; public canvas() { super( true ); /* zabil? Class nasleduemiy ot Canvas ili GameCanvas dolzhen met super() prichem esli ot canvas to super pustoy esli ot game canvas to v super nado peredat boolevuyu true */ manager=new LayerManager(); try { img=Image.createImage("/fon.png"); } catch( IOException ioe ) { Form f=new Form("Strange exception"); main.link.display.setCurrent(f); } fon=initFon(); manager.append(fon); } public void run(){ Graphics g=getGraphics(); while(true){ init(g); try{ Thread.sleep(20); /* staticheskiy method */ } catch(Exception e){ Form f=new Form("Strange exception"); main.link.display.setCurrent(f); } } } public void init(Graphics g) { g.setColor(255,255,255); g.fillRect(0,0,128,160); manager.paint(g,0,0); flushGraphics(); } public TiledLayer initFon() { /* imya ne sootvetsvovalo visivaemomu */ /* img=Image.createImage("/fon.png"); izobrazheniya zhelatelno sozdavat v bloke try ... catch i v constructore classa */ TiledLayer tl=new TiledLayer(20,10,img,16,16); for(int i=0;i<9;i++){ for(int j=0;j<20;j++){ tl.setCell(j,i,1); } } for(int i=0;i<20;i++){ tl.setCell(i,10,1); } return tl; } public void start(){ t=new Thread(this); t.start(); } }