SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Plus 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
 

Dernier

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Dernier (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

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