package hello; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.Sprite; import javax.microedition.lcdui.game.LayerManager; import javax.microedition.lcdui.Graphics; public class Tiles extends MIDlet { Board b; public Tiles() { b = new Board(this); } public void startApp() { Display.getDisplay(this).setCurrent(b); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } } class Board extends Canvas implements CommandListener { private GameDesign gameDesign; private Sprite cursor; private LayerManager lm; public Graphics g; public int x = 0; MIDlet midlet; Command exitCommand; public Board(MIDlet midlet_) { try{ this.lm = new LayerManager(); this.gameDesign = new GameDesign(); this.cursor = this.gameDesign.getCurs(); this.cursor.defineReferencePixel(cursor.getWidth(), cursor.getHeight()); this.cursor.move(0, 0); this.lm.append(cursor); this.lm.setViewWindow(0, 0, this.getWidth(), this.getHeight()); } catch(Exception x){} exitCommand = new Command("Exit", Command.SCREEN, 2); addCommand(exitCommand); setCommandListener(this); ////////////////////=============== repaint(); } public void commandAction(Command c, Displayable d) { if (c == exitCommand) { midlet.notifyDestroyed(); } } public void paint(Graphics g) { g.setColor(255); g.fillRect(0, 0, 100, 100); //g.drawImage(im, x, 10, Graphics.LEFT | Graphics.TOP); this.cursor.paint(g); } public void keyPressed(int code) { int game = getGameAction(code); switch (game) { case Canvas.UP: System.out.println("Canvas.UP"); break; case Canvas.DOWN: System.out.println("Canvas.DOWN"); break; case Canvas.LEFT: System.out.println("Canvas.LEFT"); break; case Canvas.RIGHT: x++; this.cursor.setPosition(x, cursor.getY()); this.cursor.paint(g); //<===============NULL POINTER EXCEPTION System.out.println("Canvas.RIGHT"); break; } } }
paint(Graphics g)
Graphics g
Board.repaint()
Board.repaint(x, y, width, height)
Canvas
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)