扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
图1 |
Image logo = null; try { logo = Image.createImage("/logo.png"); }catch (IOException e) {} Alert splashScreen = new Alert(null, "郎锐2004年作\n版权所有(c)\n2004--2005", logo, AlertType.INFO); splashScreen.setTimeout(4000); // 延迟4秒 |
图2 图3 图4 图5 |
choosePieceScreen = new ChoosePieceScreen(this); Display.getDisplay(this).setCurrent(splashScreen, choosePieceScreen); |
super("请选择:", List.IMPLICIT); // 设置列表选择 this.midlet = midlet; append(CAT_TEXT, loadImage("/cat.png")); // 添加图象选项到列表 append(RABBIT_TEXT, loadImage("/rabbit.png")); setCommandListener(this); // 侦听按键响应 …… public void commandAction(Command arg0, Displayable arg1) { if (arg0 == List.SELECT_COMMAND){ // 检测是否为列表按键响应 // 检测用户选中的选项 boolean isPlayerCat = getString(getSelectedIndex()).equals(CAT_TEXT); midlet.choosePieceScreenDone(isPlayerCat); // 进入游戏画面 } } |
screenWidth = getWidth();// 获取屏幕大小 screenHeight = getHeight(); if (screenWidth > screenHeight) {// 计算网格大小 boardCellSize = (screenHeight - 2) / 3; boardLeft = (screenWidth - (boardCellSize * 3)) / 2; boardTop = 1; }else{ boardCellSize = (screenWidth - 2) / 3; boardLeft = 1; boardTop = (screenHeight - boardCellSize * 3) / 2; } |
g.setColor(WHITE); g.fillRect(0, 0, screenWidth, screenHeight); g.setColor(BLACK); for (int i = 0; i < 4;i++) { g.fillRect(boardLeft, boardCellSize*i+boardTop,(boardCellSize*3)+2,2); g.fillRect(boardCellSize * i + boardLeft, boardTop, 2, boardCellSize * 3); } |
private void drawCat(Graphics g, int x, int y) { Image image = null; try {// 装载图象 image = Image.createImage("/cat.png"); }catch (Exception e) {} g.drawImage(image, x + 1, y + 1, 0); // 在指定位置绘制图象 } |
Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM); // 设置字体 int strHeight = font.getHeight(); int statusMsgWidth = font.stringWidth(statusMsg); int tallyMsgWidth = font.stringWidth(tallyMsg); int strWidth = tallyMsgWidth; if (statusMsgWidth > tallyMsgWidth) strWidth = statusMsgWidth; int x = (screenWidth - strWidth) / 2; // 计算字符绘制位置 x = x < 0 ? 0 : x; int y = (screenHeight - 2 * strHeight) / 2; y = y < 0 ? 0 : y; g.setColor(WHITE); // 白色清空画布 g.fillRect(0, 0, screenWidth, screenHeight); g.setColor(BLACK); // 黑色显示信息 g.drawString(statusMsg, x, y, (Graphics.TOP | Graphics.LEFT)); g.drawString(tallyMsg, x, (y + 1 + strHeight), (Graphics.TOP | Graphics.LEFT)); |
if (arg0 == exitCommand) // 退出 midlet.quit(); else if (arg0 == newGameCommand) // 开始游戏 initialize(); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者