SlideShare una empresa de Scribd logo
1 de 12
LẬP TRÌNH J2ME CHO THIẾT BỊ DI ĐỘNG
PHẦN 5

Giáo viên : Trịnh Thị Vân Anh

Hà nội, 8-2007
Eliminator: Game Menu, EliminatorBasicMenu (1)


Basic Main Menu

import javax.microedition.lcdui.*;
public class MainMenuScreen extends List
implements CommandListener {
private Eliminator midlet;
private Command selectCommand = new
Command("Select", Command.ITEM,1);
private Command exitCommand = new
Command("Exit", Command.EXIT,1);
private Alert alert;
public MainMenuScreen(Eliminator midlet) {
super("Eliminator",Choice.IMPLICIT);
this.midlet = midlet;
append("New Game",null);
append("Settings",null);
append("High Scores", null);
append("Help",null);
append("About",null);

addCommand(exitCommand);
addCommand(selectCommand);
setCommandListener(this);
}
public void commandAction(Command c,
Displayable d) {
if (c == exitCommand) {
midlet.mainMenuScreenQuit();
return;
} else if (c == selectCommand) {
processMenu(); return;
} else {
processMenu(); return;
}
}

2
Eliminator: Game Menu, EliminatorBasicMenu (2)
private void processMenu() {
try {
List down = (List)midlet.display.getCurrent();
switch (down.getSelectedIndex()) {
case 0: scnNewGame(); break;
case 1: scnSettings(); break;
case 2: scnHighScores(); break;
case 3: scnHelp(); break;
case 4: scnAbout(); break;};
} catch (Exception ex) {

alert = new
Alert("Settings","Settings.......",null,null);

// Proper Error Handling should be done here

,"High Scores.......",null,null);

System.out.println("processMenu::"+ex);} }

alert.setTimeout(Alert.FOREVER);

private void scnNewGame() {

alert.setType(AlertType.INFO);

midlet.mainMenuScreenShow(null); }

midlet.mainMenuScreenShow(alert);

private void scnSettings() {

}

alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.INFO);
midlet.mainMenuScreenShow(alert);
}
private void scnHighScores() {
alert = new Alert("High Scores"

3
Eliminator: Game Menu, EliminatorBasicMenu (3)
private void scnHelp() {
alert = new Alert("Help","Help....................",null,null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.INFO);
midlet.mainMenuScreenShow(alert);
}
private void scnAbout() {
alert = new Alert("About","EliminatornVersion 1.0.0nby Jason Lam",null,null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.INFO);
midlet.mainMenuScreenShow(alert);
}
}

4
Eliminator: Game Menu, EliminatorBasicMenu (4)


Main Midlet Source Code:

import javax.microedition.midlet.*;

isSplash = false;

import javax.microedition.lcdui.*;

try {

public class Eliminator extends MIDlet {

splashLogo =Image.createImage("/splash.png");

protected Display display;

new SplashScreen(display, mainMenuScreen,
splashLogo,3000);

private Image splashLogo;
private boolean isSplash = true;
MainMenuScreen mainMenuScreen;
public Eliminator() {}
public void startApp() {
display = Display.getDisplay(this);
mainMenuScreen = new
MainMenuScreen(this);

} catch(Exception ex) {
mainMenuScreenShow(null);
}
} else {
mainMenuScreenShow(null);
}
}

if(isSplash) {

5
Eliminator: Game Menu, EliminatorBasicMenu (5)
public Display getDisplay() {
return display;}
public void pauseApp() {}
public void destroyApp(boolean unconditional)
{
System.gc();
notifyDestroyed();
}
private Image createImage(String filename) {
Image image = null;
try {
image = Image.createImage(filename);
} catch (Exception e) {
}return image;
}

public void mainMenuScreenShow(Alert alert)
{
if (alert==null)
display.setCurrent(mainMenuScreen);
else
display.setCurrent(alert,mainMenuScreen);
}
public void mainMenuScreenQuit() {
destroyApp(true);
}
}

6
Eliminator: Game Menu, EliminatorSubMenu (1)
private void scnNewGame() {
midlet.mainMenuScreenShow();
}
private void scnSettings() {
midlet.settingsScreenShow();
}
private void scnHighScore() {
midlet.highScoreScreenShow();
}
private void scnHelp() {
midlet.helpScreenShow();
}
private void scnAbout() {
midlet.aboutScreenShow();
}
}

7
Eliminator: Game Menu, EliminatorSubMenu (2)
High Score Screen Source Code:
import javax.microedition.lcdui.*;
public class HighScoreScreen extends Form implements CommandListener {
private Eliminator midlet;
private Command backCommand = new Command("Back", Command.BACK,1);
private Command resetCommand = new Command("Rest", Command.SCREEN,1);
public HighScoreScreen (Eliminator midlet) {
super("High Score");
this.midlet = midlet;
StringItem stringItem = new StringItem(null,"JL 100nJL 50nJL 10");
append(stringItem);
addCommand(backCommand);
addCommand(resetCommand); setCommandListener(this); }
public void commandAction(Command c, Displayable d) {
if (c == backCommand) {
midlet.mainMenuScreenShow();
return;
}if (c == resetCommand) { // not implemented yet
System.out.println("Reset High Scores Not Implemented Yet");
}}}


8
Eliminator: Game Menu, EliminatorSubMenu (3)
Help Screen Source Code:
import javax.microedition.lcdui.*;
public class HelpScreen extends Form implements CommandListener {
private Eliminator midlet;
private Command backCommand = new Command("Back", Command.BACK, 1);
public HelpScreen (Eliminator midlet) {
super("Help");
this.midlet = midlet;
StringItem stringItem = new StringItem(null,"It is the year 3023, many things have changed over
the years " +
…………
);
append(stringItem); addCommand(backCommand);
setCommandListener(this); }
public void commandAction(Command c, Displayable d) {
if (c == backCommand) {
midlet.mainMenuScreenShow();
return;
}}}


9
Eliminator: Game Menu, EliminatorSubMenu (4)
About Screen Source Code:
import javax.microedition.lcdui.*;
public class AboutScreen extends Form implements CommandListener {
private Eliminator midlet;
private Command backCommand = new Command("Back", Command.BACK, 1);
public AboutScreen (Eliminator midlet) {
super("About");
this.midlet = midlet;
StringItem stringItem = new StringItem(null,"EliminatornVersion 1.0.0nBy Jason Lam");
append(stringItem);
addCommand(backCommand); setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if (c == backCommand) {
midlet.mainMenuScreenShow();
return;
}}}


10
Eliminator: Terrain (Scrolling Background)
private TiledLayer loadTerrain() throws
Exception {
Image tileImages =
Image.createImage("/terrain.png");
TiledLayer tiledLayer = new
TiledLayer(TILE_NUM_COL,TILE_NUM_
ROW,tileImages,TILE_WIDTH,TILE_HEI
GHT);
// Define Terrain Map
int[][] map = {
{0,0,0,0,0,0}, {3,0,0,0,0,0}, {6,0,0,0,0,0},
{6,0,0,0,1,2}, {6,0,0,0,4,5}, {6,0,0,0,7,8},
{6,0,0,0,0,0},{9,0,1,2,3,0}, {0,0,4,5,6,0},
{0,0,7,8,9,0},{0,0,0,0,0,0}, {0,0,0,0,0,0},
{0,0,0,0,0,0},{3,0,0,0,0,0}, {6,0,0,0,0,0},

{6,0,0,0,1,2}, {6,0,0,0,4,5}, {6,0,0,0,7,8},
{6,0,0,0,0,0}, {9,0,1,2,3,0}, {0,0,4,5,6,0},
{0,0,7,8,9,0}, {0,0,0,0,0,0},{0,0,0,0,0,0},
{0,0,0,0,0,0},{3,0,0,0,0,0}, {6,0,0,0,0,0},
{6,0,0,0,1,2},{6,0,0,0,4,5}, {6,0,0,0,7,8},
{6,0,0,0,0,0},{9,0,0,0,0,0}, {0,0,0,0,0,0},
{0,0,0,0,0,0},{0,0,0,0,0,0}, {3,0,0,0,0,1}
};

// Map Terrain Map with actual graphic from terrain.png

for (int row=0; row<TILE_NUM_ROW; row++) {
for (int col=0; col<TILE_NUM_COL; col++) {
tiledLayer.setCell(col,row,map[row][col]);
}
}return tiledLayer;
}
Ví dụ: EliminatorScrolling

11
Eliminator: Player , ví dụ : EliminatorPlayer
Player Sprite
public class PlayerSprite extends Sprite {
private static final int MOVE = 3;
private int x,y;
private int scnWidth,scnHeight;
private int frameWidth, frameHeight;
private int frame;
private int lives;
public PlayerSprite(Image image, int frameWidth,
int frameHeight, int scnWidth, int scnHeight)
throws Exception {
super(image, frameWidth, frameHeight);
x = frameWidth/2;
y = frameHeight/2;
this.scnWidth = scnWidth;
this.scnHeight = scnHeight;
this.frameWidth = frameWidth;
this.frameHeight = frameHeight;
this.frame = 1; this.lives = 3;}


public void startPosition() {
setPosition(scnWidth/2,scnHeight/2);}
public void moveLeft() {
getXY();
if (x - MOVE > 0)
move(MOVE * -1,0);}
public void moveRight() {
getXY();
if (x + MOVE + frameWidth < scnWidth)
move(MOVE,0);}
public void moveUp() {
getXY();
if (y - MOVE > 0)
move(0,MOVE * -1);}
public void moveDown() {
getXY();
if (y + MOVE + frameHeight < scnHeight)
move(0,MOVE);}

12

Más contenido relacionado

La actualidad más candente

The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.7 book - Part 59 of 196The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.7 book - Part 59 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 59 of 189
The Ring programming language version 1.6 book - Part 59 of 189The Ring programming language version 1.6 book - Part 59 of 189
The Ring programming language version 1.6 book - Part 59 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 10 of 31
The Ring programming language version 1.5 book - Part 10 of 31The Ring programming language version 1.5 book - Part 10 of 31
The Ring programming language version 1.5 book - Part 10 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 49 of 180
The Ring programming language version 1.5.1 book - Part 49 of 180The Ring programming language version 1.5.1 book - Part 49 of 180
The Ring programming language version 1.5.1 book - Part 49 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.4 book - Part 55 of 185The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.4 book - Part 55 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 62 of 196
The Ring programming language version 1.7 book - Part 62 of 196The Ring programming language version 1.7 book - Part 62 of 196
The Ring programming language version 1.7 book - Part 62 of 196Mahmoud Samir Fayed
 
Create xo game in android studio
Create xo game in android studioCreate xo game in android studio
Create xo game in android studioMahmoodGhaemMaghami
 
The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185Mahmoud Samir Fayed
 
551 pd fsam_fayed_ring_doc_1.5.2
551 pd fsam_fayed_ring_doc_1.5.2551 pd fsam_fayed_ring_doc_1.5.2
551 pd fsam_fayed_ring_doc_1.5.2Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 66 of 210
The Ring programming language version 1.9 book - Part 66 of 210The Ring programming language version 1.9 book - Part 66 of 210
The Ring programming language version 1.9 book - Part 66 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.5.2 book - Part 54 of 181The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.5.2 book - Part 54 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 50 of 184
The Ring programming language version 1.5.3 book - Part 50 of 184The Ring programming language version 1.5.3 book - Part 50 of 184
The Ring programming language version 1.5.3 book - Part 50 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 66 of 184
The Ring programming language version 1.5.3 book - Part 66 of 184The Ring programming language version 1.5.3 book - Part 66 of 184
The Ring programming language version 1.5.3 book - Part 66 of 184Mahmoud Samir Fayed
 

La actualidad más candente (20)

The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212
 
The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.7 book - Part 59 of 196The Ring programming language version 1.7 book - Part 59 of 196
The Ring programming language version 1.7 book - Part 59 of 196
 
Phonegap for Android
Phonegap for AndroidPhonegap for Android
Phonegap for Android
 
The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202The Ring programming language version 1.8 book - Part 64 of 202
The Ring programming language version 1.8 book - Part 64 of 202
 
The Ring programming language version 1.6 book - Part 59 of 189
The Ring programming language version 1.6 book - Part 59 of 189The Ring programming language version 1.6 book - Part 59 of 189
The Ring programming language version 1.6 book - Part 59 of 189
 
The Ring programming language version 1.5 book - Part 10 of 31
The Ring programming language version 1.5 book - Part 10 of 31The Ring programming language version 1.5 book - Part 10 of 31
The Ring programming language version 1.5 book - Part 10 of 31
 
The Ring programming language version 1.5.1 book - Part 49 of 180
The Ring programming language version 1.5.1 book - Part 49 of 180The Ring programming language version 1.5.1 book - Part 49 of 180
The Ring programming language version 1.5.1 book - Part 49 of 180
 
The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.4 book - Part 55 of 185The Ring programming language version 1.5.4 book - Part 55 of 185
The Ring programming language version 1.5.4 book - Part 55 of 185
 
The Ring programming language version 1.7 book - Part 62 of 196
The Ring programming language version 1.7 book - Part 62 of 196The Ring programming language version 1.7 book - Part 62 of 196
The Ring programming language version 1.7 book - Part 62 of 196
 
Create xo game in android studio
Create xo game in android studioCreate xo game in android studio
Create xo game in android studio
 
The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185
 
551 pd fsam_fayed_ring_doc_1.5.2
551 pd fsam_fayed_ring_doc_1.5.2551 pd fsam_fayed_ring_doc_1.5.2
551 pd fsam_fayed_ring_doc_1.5.2
 
The Ring programming language version 1.9 book - Part 66 of 210
The Ring programming language version 1.9 book - Part 66 of 210The Ring programming language version 1.9 book - Part 66 of 210
The Ring programming language version 1.9 book - Part 66 of 210
 
The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180The Ring programming language version 1.5.1 book - Part 56 of 180
The Ring programming language version 1.5.1 book - Part 56 of 180
 
The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212The Ring programming language version 1.10 book - Part 67 of 212
The Ring programming language version 1.10 book - Part 67 of 212
 
The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.5.2 book - Part 54 of 181The Ring programming language version 1.5.2 book - Part 54 of 181
The Ring programming language version 1.5.2 book - Part 54 of 181
 
The Ring programming language version 1.5.3 book - Part 50 of 184
The Ring programming language version 1.5.3 book - Part 50 of 184The Ring programming language version 1.5.3 book - Part 50 of 184
The Ring programming language version 1.5.3 book - Part 50 of 184
 
The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.3 book - Part 40 of 88
 
The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189The Ring programming language version 1.6 book - Part 57 of 189
The Ring programming language version 1.6 book - Part 57 of 189
 
The Ring programming language version 1.5.3 book - Part 66 of 184
The Ring programming language version 1.5.3 book - Part 66 of 184The Ring programming language version 1.5.3 book - Part 66 of 184
The Ring programming language version 1.5.3 book - Part 66 of 184
 

Destacado

Marco común para las normas de Contabilidad
Marco común para las normas de ContabilidadMarco común para las normas de Contabilidad
Marco común para las normas de ContabilidadSerginaFontalvo
 
Callsheet
CallsheetCallsheet
CallsheetGMeah
 
Los angeles del sistal legislacion 2
Los angeles del sistal legislacion 2Los angeles del sistal legislacion 2
Los angeles del sistal legislacion 2poli_morote
 
Congressional Briefing 10222009
Congressional Briefing 10222009Congressional Briefing 10222009
Congressional Briefing 10222009jaythomas
 
Changing Oceans Expedition 2012 - Laura Wicks, MASTS
Changing Oceans Expedition 2012 - Laura Wicks, MASTSChanging Oceans Expedition 2012 - Laura Wicks, MASTS
Changing Oceans Expedition 2012 - Laura Wicks, MASTSHeriot-Watt University
 

Destacado (7)

Marco común para las normas de Contabilidad
Marco común para las normas de ContabilidadMarco común para las normas de Contabilidad
Marco común para las normas de Contabilidad
 
Callsheet
CallsheetCallsheet
Callsheet
 
Los angeles del sistal legislacion 2
Los angeles del sistal legislacion 2Los angeles del sistal legislacion 2
Los angeles del sistal legislacion 2
 
[Whitepaper] Morden PR
[Whitepaper] Morden PR[Whitepaper] Morden PR
[Whitepaper] Morden PR
 
Congressional Briefing 10222009
Congressional Briefing 10222009Congressional Briefing 10222009
Congressional Briefing 10222009
 
Con trai thời @
Con trai thời @Con trai thời @
Con trai thời @
 
Changing Oceans Expedition 2012 - Laura Wicks, MASTS
Changing Oceans Expedition 2012 - Laura Wicks, MASTSChanging Oceans Expedition 2012 - Laura Wicks, MASTS
Changing Oceans Expedition 2012 - Laura Wicks, MASTS
 

Similar a J2 me 07_5

ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfrajkumarm401
 
Whenever I run my application my Game appears with the pict.pdf
Whenever I run my application my Game appears with the pict.pdfWhenever I run my application my Game appears with the pict.pdf
Whenever I run my application my Game appears with the pict.pdfaarthitimesgd
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfaakarcreations1
 
Contoh bahan latihan programan mobile java
Contoh bahan latihan programan mobile javaContoh bahan latihan programan mobile java
Contoh bahan latihan programan mobile javaJurnal IT
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Kuldeep Jain
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3Jieyi Wu
 
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfapexcomputer54
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfanjandavid
 
Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programsSumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programsAbhijit Borah
 
Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)Danny Preussler
 
Spin Up Desktop Apps with Electron.js
Spin Up Desktop Apps with Electron.jsSpin Up Desktop Apps with Electron.js
Spin Up Desktop Apps with Electron.jsSteve Godin
 
Tic Tac Toe game with GUI please dont copy and paste from google. .pdf
Tic Tac Toe game with GUI please dont copy and paste from google. .pdfTic Tac Toe game with GUI please dont copy and paste from google. .pdf
Tic Tac Toe game with GUI please dont copy and paste from google. .pdfformaxekochi
 

Similar a J2 me 07_5 (20)

ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
 
Whenever I run my application my Game appears with the pict.pdf
Whenever I run my application my Game appears with the pict.pdfWhenever I run my application my Game appears with the pict.pdf
Whenever I run my application my Game appears with the pict.pdf
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdf
 
662305 LAB12
662305 LAB12662305 LAB12
662305 LAB12
 
Contoh bahan latihan programan mobile java
Contoh bahan latihan programan mobile javaContoh bahan latihan programan mobile java
Contoh bahan latihan programan mobile java
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
ETM Server
ETM ServerETM Server
ETM Server
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3
 
Flappy bird
Flappy birdFlappy bird
Flappy bird
 
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdf
 
Applications
ApplicationsApplications
Applications
 
Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programsSumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
 
Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)
 
662305 LAB13
662305 LAB13662305 LAB13
662305 LAB13
 
Spin Up Desktop Apps with Electron.js
Spin Up Desktop Apps with Electron.jsSpin Up Desktop Apps with Electron.js
Spin Up Desktop Apps with Electron.js
 
Tic Tac Toe game with GUI please dont copy and paste from google. .pdf
Tic Tac Toe game with GUI please dont copy and paste from google. .pdfTic Tac Toe game with GUI please dont copy and paste from google. .pdf
Tic Tac Toe game with GUI please dont copy and paste from google. .pdf
 
Sequence diagrams
Sequence diagramsSequence diagrams
Sequence diagrams
 
Tdd in unity
Tdd in unityTdd in unity
Tdd in unity
 

Más de vanliemtb

Tran van chien
Tran van chienTran van chien
Tran van chienvanliemtb
 
Tom tat lv th s nguyen xuan bach
Tom tat lv th s nguyen xuan bachTom tat lv th s nguyen xuan bach
Tom tat lv th s nguyen xuan bachvanliemtb
 
Tom tat lv th s ha quang thang 2012
Tom tat lv th s ha quang thang 2012Tom tat lv th s ha quang thang 2012
Tom tat lv th s ha quang thang 2012vanliemtb
 
Tóm tat lv lt.hiệu
Tóm tat lv lt.hiệuTóm tat lv lt.hiệu
Tóm tat lv lt.hiệuvanliemtb
 
Ttlats dinh thi thu phong
Ttlats dinh thi thu phongTtlats dinh thi thu phong
Ttlats dinh thi thu phongvanliemtb
 
Ttlv chu chi linh
Ttlv chu chi linhTtlv chu chi linh
Ttlv chu chi linhvanliemtb
 
Ttlv lưu thanh huy
Ttlv lưu thanh huyTtlv lưu thanh huy
Ttlv lưu thanh huyvanliemtb
 
Ttlv hoang dinh hung
Ttlv hoang dinh hungTtlv hoang dinh hung
Ttlv hoang dinh hungvanliemtb
 
Ttlats dinh thi thu phong
Ttlats dinh thi thu phongTtlats dinh thi thu phong
Ttlats dinh thi thu phongvanliemtb
 
Vi quang hieu
Vi quang hieuVi quang hieu
Vi quang hieuvanliemtb
 
Tom tat lv th s ha quang thang 2012
Tom tat lv th s ha quang thang 2012Tom tat lv th s ha quang thang 2012
Tom tat lv th s ha quang thang 2012vanliemtb
 
Nguyễn ngọc ánh
Nguyễn ngọc ánhNguyễn ngọc ánh
Nguyễn ngọc ánhvanliemtb
 
Lv th s.ck hanh.10
Lv th s.ck hanh.10Lv th s.ck hanh.10
Lv th s.ck hanh.10vanliemtb
 
Nghien+cuu++he+thong+truyen+dan+quang
Nghien+cuu++he+thong+truyen+dan+quangNghien+cuu++he+thong+truyen+dan+quang
Nghien+cuu++he+thong+truyen+dan+quangvanliemtb
 
Mang va cac cong nghe truy nhap
Mang va cac cong nghe truy nhapMang va cac cong nghe truy nhap
Mang va cac cong nghe truy nhapvanliemtb
 
Thong tin quang 2
Thong tin quang 2Thong tin quang 2
Thong tin quang 2vanliemtb
 
Ky thuat so phan 8
Ky thuat so phan 8Ky thuat so phan 8
Ky thuat so phan 8vanliemtb
 
Bao caototnghiep ve vpn
Bao caototnghiep ve vpnBao caototnghiep ve vpn
Bao caototnghiep ve vpnvanliemtb
 

Más de vanliemtb (20)

Tran van chien
Tran van chienTran van chien
Tran van chien
 
Tom tat lv th s nguyen xuan bach
Tom tat lv th s nguyen xuan bachTom tat lv th s nguyen xuan bach
Tom tat lv th s nguyen xuan bach
 
Tom tat lv th s ha quang thang 2012
Tom tat lv th s ha quang thang 2012Tom tat lv th s ha quang thang 2012
Tom tat lv th s ha quang thang 2012
 
00050001334
0005000133400050001334
00050001334
 
Tóm tat lv lt.hiệu
Tóm tat lv lt.hiệuTóm tat lv lt.hiệu
Tóm tat lv lt.hiệu
 
Ttlats dinh thi thu phong
Ttlats dinh thi thu phongTtlats dinh thi thu phong
Ttlats dinh thi thu phong
 
Ttlv chu chi linh
Ttlv chu chi linhTtlv chu chi linh
Ttlv chu chi linh
 
Ttlv lưu thanh huy
Ttlv lưu thanh huyTtlv lưu thanh huy
Ttlv lưu thanh huy
 
Ttlv hoang dinh hung
Ttlv hoang dinh hungTtlv hoang dinh hung
Ttlv hoang dinh hung
 
Ttlats dinh thi thu phong
Ttlats dinh thi thu phongTtlats dinh thi thu phong
Ttlats dinh thi thu phong
 
V l0 02714
V l0 02714V l0 02714
V l0 02714
 
Vi quang hieu
Vi quang hieuVi quang hieu
Vi quang hieu
 
Tom tat lv th s ha quang thang 2012
Tom tat lv th s ha quang thang 2012Tom tat lv th s ha quang thang 2012
Tom tat lv th s ha quang thang 2012
 
Nguyễn ngọc ánh
Nguyễn ngọc ánhNguyễn ngọc ánh
Nguyễn ngọc ánh
 
Lv th s.ck hanh.10
Lv th s.ck hanh.10Lv th s.ck hanh.10
Lv th s.ck hanh.10
 
Nghien+cuu++he+thong+truyen+dan+quang
Nghien+cuu++he+thong+truyen+dan+quangNghien+cuu++he+thong+truyen+dan+quang
Nghien+cuu++he+thong+truyen+dan+quang
 
Mang va cac cong nghe truy nhap
Mang va cac cong nghe truy nhapMang va cac cong nghe truy nhap
Mang va cac cong nghe truy nhap
 
Thong tin quang 2
Thong tin quang 2Thong tin quang 2
Thong tin quang 2
 
Ky thuat so phan 8
Ky thuat so phan 8Ky thuat so phan 8
Ky thuat so phan 8
 
Bao caototnghiep ve vpn
Bao caototnghiep ve vpnBao caototnghiep ve vpn
Bao caototnghiep ve vpn
 

Último

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Último (20)

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

J2 me 07_5

  • 1. LẬP TRÌNH J2ME CHO THIẾT BỊ DI ĐỘNG PHẦN 5 Giáo viên : Trịnh Thị Vân Anh Hà nội, 8-2007
  • 2. Eliminator: Game Menu, EliminatorBasicMenu (1)  Basic Main Menu import javax.microedition.lcdui.*; public class MainMenuScreen extends List implements CommandListener { private Eliminator midlet; private Command selectCommand = new Command("Select", Command.ITEM,1); private Command exitCommand = new Command("Exit", Command.EXIT,1); private Alert alert; public MainMenuScreen(Eliminator midlet) { super("Eliminator",Choice.IMPLICIT); this.midlet = midlet; append("New Game",null); append("Settings",null); append("High Scores", null); append("Help",null); append("About",null); addCommand(exitCommand); addCommand(selectCommand); setCommandListener(this); } public void commandAction(Command c, Displayable d) { if (c == exitCommand) { midlet.mainMenuScreenQuit(); return; } else if (c == selectCommand) { processMenu(); return; } else { processMenu(); return; } } 2
  • 3. Eliminator: Game Menu, EliminatorBasicMenu (2) private void processMenu() { try { List down = (List)midlet.display.getCurrent(); switch (down.getSelectedIndex()) { case 0: scnNewGame(); break; case 1: scnSettings(); break; case 2: scnHighScores(); break; case 3: scnHelp(); break; case 4: scnAbout(); break;}; } catch (Exception ex) { alert = new Alert("Settings","Settings.......",null,null); // Proper Error Handling should be done here ,"High Scores.......",null,null); System.out.println("processMenu::"+ex);} } alert.setTimeout(Alert.FOREVER); private void scnNewGame() { alert.setType(AlertType.INFO); midlet.mainMenuScreenShow(null); } midlet.mainMenuScreenShow(alert); private void scnSettings() { } alert.setTimeout(Alert.FOREVER); alert.setType(AlertType.INFO); midlet.mainMenuScreenShow(alert); } private void scnHighScores() { alert = new Alert("High Scores" 3
  • 4. Eliminator: Game Menu, EliminatorBasicMenu (3) private void scnHelp() { alert = new Alert("Help","Help....................",null,null); alert.setTimeout(Alert.FOREVER); alert.setType(AlertType.INFO); midlet.mainMenuScreenShow(alert); } private void scnAbout() { alert = new Alert("About","EliminatornVersion 1.0.0nby Jason Lam",null,null); alert.setTimeout(Alert.FOREVER); alert.setType(AlertType.INFO); midlet.mainMenuScreenShow(alert); } } 4
  • 5. Eliminator: Game Menu, EliminatorBasicMenu (4)  Main Midlet Source Code: import javax.microedition.midlet.*; isSplash = false; import javax.microedition.lcdui.*; try { public class Eliminator extends MIDlet { splashLogo =Image.createImage("/splash.png"); protected Display display; new SplashScreen(display, mainMenuScreen, splashLogo,3000); private Image splashLogo; private boolean isSplash = true; MainMenuScreen mainMenuScreen; public Eliminator() {} public void startApp() { display = Display.getDisplay(this); mainMenuScreen = new MainMenuScreen(this); } catch(Exception ex) { mainMenuScreenShow(null); } } else { mainMenuScreenShow(null); } } if(isSplash) { 5
  • 6. Eliminator: Game Menu, EliminatorBasicMenu (5) public Display getDisplay() { return display;} public void pauseApp() {} public void destroyApp(boolean unconditional) { System.gc(); notifyDestroyed(); } private Image createImage(String filename) { Image image = null; try { image = Image.createImage(filename); } catch (Exception e) { }return image; } public void mainMenuScreenShow(Alert alert) { if (alert==null) display.setCurrent(mainMenuScreen); else display.setCurrent(alert,mainMenuScreen); } public void mainMenuScreenQuit() { destroyApp(true); } } 6
  • 7. Eliminator: Game Menu, EliminatorSubMenu (1) private void scnNewGame() { midlet.mainMenuScreenShow(); } private void scnSettings() { midlet.settingsScreenShow(); } private void scnHighScore() { midlet.highScoreScreenShow(); } private void scnHelp() { midlet.helpScreenShow(); } private void scnAbout() { midlet.aboutScreenShow(); } } 7
  • 8. Eliminator: Game Menu, EliminatorSubMenu (2) High Score Screen Source Code: import javax.microedition.lcdui.*; public class HighScoreScreen extends Form implements CommandListener { private Eliminator midlet; private Command backCommand = new Command("Back", Command.BACK,1); private Command resetCommand = new Command("Rest", Command.SCREEN,1); public HighScoreScreen (Eliminator midlet) { super("High Score"); this.midlet = midlet; StringItem stringItem = new StringItem(null,"JL 100nJL 50nJL 10"); append(stringItem); addCommand(backCommand); addCommand(resetCommand); setCommandListener(this); } public void commandAction(Command c, Displayable d) { if (c == backCommand) { midlet.mainMenuScreenShow(); return; }if (c == resetCommand) { // not implemented yet System.out.println("Reset High Scores Not Implemented Yet"); }}}  8
  • 9. Eliminator: Game Menu, EliminatorSubMenu (3) Help Screen Source Code: import javax.microedition.lcdui.*; public class HelpScreen extends Form implements CommandListener { private Eliminator midlet; private Command backCommand = new Command("Back", Command.BACK, 1); public HelpScreen (Eliminator midlet) { super("Help"); this.midlet = midlet; StringItem stringItem = new StringItem(null,"It is the year 3023, many things have changed over the years " + ………… ); append(stringItem); addCommand(backCommand); setCommandListener(this); } public void commandAction(Command c, Displayable d) { if (c == backCommand) { midlet.mainMenuScreenShow(); return; }}}  9
  • 10. Eliminator: Game Menu, EliminatorSubMenu (4) About Screen Source Code: import javax.microedition.lcdui.*; public class AboutScreen extends Form implements CommandListener { private Eliminator midlet; private Command backCommand = new Command("Back", Command.BACK, 1); public AboutScreen (Eliminator midlet) { super("About"); this.midlet = midlet; StringItem stringItem = new StringItem(null,"EliminatornVersion 1.0.0nBy Jason Lam"); append(stringItem); addCommand(backCommand); setCommandListener(this); } public void commandAction(Command c, Displayable d) { if (c == backCommand) { midlet.mainMenuScreenShow(); return; }}}  10
  • 11. Eliminator: Terrain (Scrolling Background) private TiledLayer loadTerrain() throws Exception { Image tileImages = Image.createImage("/terrain.png"); TiledLayer tiledLayer = new TiledLayer(TILE_NUM_COL,TILE_NUM_ ROW,tileImages,TILE_WIDTH,TILE_HEI GHT); // Define Terrain Map int[][] map = { {0,0,0,0,0,0}, {3,0,0,0,0,0}, {6,0,0,0,0,0}, {6,0,0,0,1,2}, {6,0,0,0,4,5}, {6,0,0,0,7,8}, {6,0,0,0,0,0},{9,0,1,2,3,0}, {0,0,4,5,6,0}, {0,0,7,8,9,0},{0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0},{3,0,0,0,0,0}, {6,0,0,0,0,0}, {6,0,0,0,1,2}, {6,0,0,0,4,5}, {6,0,0,0,7,8}, {6,0,0,0,0,0}, {9,0,1,2,3,0}, {0,0,4,5,6,0}, {0,0,7,8,9,0}, {0,0,0,0,0,0},{0,0,0,0,0,0}, {0,0,0,0,0,0},{3,0,0,0,0,0}, {6,0,0,0,0,0}, {6,0,0,0,1,2},{6,0,0,0,4,5}, {6,0,0,0,7,8}, {6,0,0,0,0,0},{9,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0},{0,0,0,0,0,0}, {3,0,0,0,0,1} }; // Map Terrain Map with actual graphic from terrain.png for (int row=0; row<TILE_NUM_ROW; row++) { for (int col=0; col<TILE_NUM_COL; col++) { tiledLayer.setCell(col,row,map[row][col]); } }return tiledLayer; } Ví dụ: EliminatorScrolling 11
  • 12. Eliminator: Player , ví dụ : EliminatorPlayer Player Sprite public class PlayerSprite extends Sprite { private static final int MOVE = 3; private int x,y; private int scnWidth,scnHeight; private int frameWidth, frameHeight; private int frame; private int lives; public PlayerSprite(Image image, int frameWidth, int frameHeight, int scnWidth, int scnHeight) throws Exception { super(image, frameWidth, frameHeight); x = frameWidth/2; y = frameHeight/2; this.scnWidth = scnWidth; this.scnHeight = scnHeight; this.frameWidth = frameWidth; this.frameHeight = frameHeight; this.frame = 1; this.lives = 3;}  public void startPosition() { setPosition(scnWidth/2,scnHeight/2);} public void moveLeft() { getXY(); if (x - MOVE > 0) move(MOVE * -1,0);} public void moveRight() { getXY(); if (x + MOVE + frameWidth < scnWidth) move(MOVE,0);} public void moveUp() { getXY(); if (y - MOVE > 0) move(0,MOVE * -1);} public void moveDown() { getXY(); if (y + MOVE + frameHeight < scnHeight) move(0,MOVE);} 12