public abstract class Screen extends GameCanvas { protected final int screenWidth; // protected final int screenHeight; // protected final Graphics graphics; // public Screen() { super(false); setFullScreenMode(true); screenWidth = getWidth(); screenHeight = getHeight(); graphics = getGraphics(); } //, , public abstract void start(); }
Object -> GameCanvas -> Screen -> MyScreen
public class MIDletStructure extends MIDlet { public static MIDletStructure midlet; // private final Display display; public MIDletStructure() { midlet = this; display = Display.getDisplay(this); } // public void setCanvas(Screen canvas) { display.setCurrent(canvas); canvas.start(); } public void startApp() {} public void pauseApp() {} public void destroyApp(boolean unconditional) {} }
public class Splash extends Screen { //, , public void start() { graphics.setColor(0xFFFFFF); graphics.fillRect(0, 0, screenWidth, screenHeight); graphics.setColor(0x000000); graphics.drawString("SPLASH", 0, 0, 0); flushGraphics(); try { Thread.sleep(10000); } catch (InterruptedException interruptedException) { System.out.println(interruptedException.getMessage()); MIDletStructure.midlet.notifyDestroyed(); } } }
public class Game extends Screen { //, , public void start() { graphics.setColor(0xFFFFFF); graphics.fillRect(0, 0, screenWidth, screenHeight); graphics.setColor(0x000000); graphics.drawString("GAME", 0, 0, 0); flushGraphics(); while (true) { try { Thread.sleep(20); } catch (InterruptedException interruptedException) { System.out.println(interruptedException.getMessage()); MIDletStructure.midlet.notifyDestroyed(); } } } }
public class MIDletStructure extends MIDlet { public static MIDletStructure midlet; // private final Display display; public final Screen splash; // “” public final Screen menu; // public final Screen game; // public MIDletStructure() { midlet = this; display = Display.getDisplay(this); splash = new Splash(); menu = new Menu(); game = new Game(); } // public void setCanvas(Screen canvas) { display.setCurrent(canvas); canvas.start(); } public void startApp() { // setCanvas(splash); } public void pauseApp() {} public void destroyApp(boolean unconditional) {} }
Main.midlet.setCanvas(Main.midlet.game);
Source: https://habr.com/ru/post/238567/
All Articles