import javax.microedition.lcdui.*; public class Game extends Canvas implements Runnable { final String[] functionList = {"Открыть","Сохранить","Параметры","Выход"}; final String[] softString = {"Меню","Линия", "Экран"}; static Game game; public int width; public int height; public int titleBarHeight; public int softBarHeight; public int titleHeightCenter; public int titleWidthCenter; public int menuPos; public int colY; public boolean isMenu; public boolean up; public boolean down; public boolean left; public boolean right; public boolean func; public Thread thread; public String myTitle = "Novel v0.1"; public Font smallFont; public Font mediumFont; public Image background; public Image flush; public Graphics context; public Source SourceCode; public int i; //?? Constructor ??// public Game () { setFullScreenMode(true); i = 0; game = this; height = getHeight(); width = getWidth(); isMenu = up = down = left = right = func = false; SourceCode = new Source(); mediumFont = Font.getFont(0, 0, Font.SIZE_MEDIUM); smallFont = Font.getFont(0, 0, Font.SIZE_SMALL); try { background = Image.createImage("/background.png"); flush = Image.createImage(width, height); } catch (java.io.IOException e) { background = Image.createImage(5, 5); } thread = new Thread(this); titleBarHeight = height / 6; softBarHeight = height / 8; titleHeightCenter = (titleBarHeight - mediumFont.getHeight () ) / 2; titleWidthCenter = (width - mediumFont.stringWidth( myTitle) ) / 2; colY = height - titleBarHeight - softBarHeight; thread.start(); } //?? Application LIfe ??// public void run () { context = flush.getGraphics(); while(true) { clearScreen(); SourceCode.draw(context, smallFont); drawSoft(); drawTitle(); if(isMenu) drawFunctionList(); try { Thread.sleep(20); } catch (java.lang.InterruptedException e) {} repaint(); } } // графика // public void clearScreen () { context.setColor(0xffffff); context.fillRect(0, 0, width, height); } public int getHeightCenter(int cred, Font font) { return ( cred - font.getHeight() ) /2; } public int getWidthCenter(String str,Font font) { return (width - font.stringWidth(str)) /2; } void drawBackground() { for(int i = 0; i < colY; i++) { context.drawImage(background, 0, titleBarHeight + i *5, 20); } } void drawFunctionList() { drawBackground(); int Pos = height - 5 * softBarHeight -5; context.setFont(smallFont); context.setColor(60, 60, 60); context.fillRect(5, Pos, width -10, 4* softBarHeight); context.setColor(0, 180,245); context.fillRect(5, Pos + menuPos* softBarHeight, width -10, softBarHeight); context.setColor (0xffffff); for(int i = 0; i < 4; i++) { context.drawString(functionList[i], getWidthCenter(functionList[i], smallFont), Pos + i * softBarHeight + getHeightCenter(titleBarHeight, smallFont) , 20); } context.setColor(60, 60, 60); context.fillRect(0, height - softBarHeight, width, softBarHeight); context.setColor(0xffffff); context.drawString ("Закрыть", 5, height - softBarHeight + getHeightCenter(softBarHeight, smallFont), 20); } void drawSoft() { int center = height - softBarHeight + getHeightCenter( softBarHeight, smallFont); context.setFont(smallFont); context.setColor(60, 60, 60); context.fillRect(0, height - softBarHeight, width, softBarHeight); context.setColor(0xffffff); context.drawString(softString[0], 5, center, 20); context.drawString(softString[1], (width - smallFont.stringWidth(softString[1]))/2, center, 20); context.drawString(softString[2], width - smallFont.stringWidth(softString[2]) -20, center, 20); } public void drawTitle(){ context.setFont(mediumFont); context.setColor(60,60,60); context.fillRect(0, 0, width, titleBarHeight); context.setColor(255, 255, 255); context.drawString(myTitle + Integer.toString(i), titleWidthCenter, titleHeightCenter, 20); i++; } public void paint(Graphics g){ g.drawImage(flush, 0,0,20); } // обработка клавиш// public void keyPressed(int key) { if (key == Canvas.FIRE) myTitle= "Fuck"; if (key == Canvas.KEY_NUM2) changeRule(); } public void keyReleased(int key) { if (key == Canvas.KEY_NUM2) changeRule(); if (key == Canvas.FIRE) myTitle= "Fuck"; } public void cursorKeys() { if (down) { if(isMenu) keyDown(); else SourceCode.moveDown(); } if (up) { if(isMenu) keyUp(); else SourceCode.moveUp(); } if (func)changeRule(); } // rule Cursors: void functionAct() { switch ( menuPos ) { case 3: Main.midlet.exit(); break; } } public void keyDown() { menuPos++; if (menuPos > 3) menuPos = 0; } public void keyUp() { menuPos--; if (menuPos < 0) menuPos = 3; } public void changeRule() { if (isMenu) isMenu = true; else isMenu = false; } }