import javax.microedition.lcdui.*;
import java.util.*;
import javax.microedition.midlet.*;
public class a extends MIDlet {
Display display;
Display pauseDisplay;
boolean isSplash = true;
b menuScreen;
public a() {
display = Display.getDisplay(this);
b menuScreen = new b(display);
display.setCurrent(menuScreen);
}
protected void startApp() throws MIDletStateChangeException {
}
protected void pauseApp() { }
protected void destroyApp(boolean flag) throws MIDletStateChangeException {}
}
import javax.microedition.lcdui.*;
public class b extends Canvas implements Runnable {
static final Font lowFont = Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_PLAIN, Font.SIZE_SMALL);
static final Font highFont = Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD, Font.SIZE_MEDIUM);
static final int lowColor = 0x000000FF;
static final int highColor = 0x00FF0000;
static final int highBGColor = 0x00CCCCCC;
static int width;
static int height;
static int startHeight;
private c next;
private Display display;
static final int spacing = highFont.getHeight()/2;
static final String[] mainMenu = {"New Game","HighScore","Settings","Help","About"};
static int menuIdx;
Thread menuThread;
public b(Display dis) {
display = dis;
width = getWidth();
height = getHeight();
next=new c();
startHeight = (highFont.getHeight() * mainMenu.length) + ((mainMenu.length-1) *
spacing);
startHeight = (height - startHeight) / 2;
menuIdx = 0;
menuThread = new Thread(this);
menuThread.start();
}
public void run() {
while(true) {
repaint();
}
}
public void paint(Graphics g) {
g.setColor(0x00FFFFFF);
g.fillRect(0,0,width,height);
for (int i=0; i<mainMenu.length; i++) {
if (i==menuIdx) {
g.setColor(highBGColor);
g.fillRect(0,startHeight + (i*highFont.getHeight()) +
spacing,width,highFont.getHeight());
g.setFont(highFont);
g.setColor(highColor);
g.drawString(mainMenu[i],(width - highFont.stringWidth(mainMenu[i])) / 2,startHeight + (i*highFont.getHeight()) + spacing,20);
} else {
g.setFont(lowFont);
g.setColor(lowColor);
g.drawString(mainMenu[i],(width - lowFont.stringWidth(mainMenu[i]) ) / 2,startHeight + (i*highFont.getHeight()) + spacing,20);
}
}
}
protected void keyPressed(int code) {
try {
if (getGameAction(code) == Canvas.UP && menuIdx - 1 >= 0) {
menuIdx--;
} else if (getGameAction(code) == Canvas.DOWN && menuIdx + 1 <
mainMenu.length) {
menuIdx++;
} else if(getGameAction(code)==Canvas.FIRE) {
if(menuIdx==0) {
next.start();
display.setCurrent(next);
} else if(menuIdx==1) {
System.out.println("High Scores selected");
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
deepak_evil wrote:was the proceedure correct for the menu screen but whats the problem why isnt the next screen loaded and why isnt why is it throwing null pointer exception whats the problem in it do real game developers use the same technique to programme games as i am doing or there is any other technique or proceedure which i am unaware of.
of i have decompiled some .class files of games from companies like gameloft the proceedure looks totally diferent.
am i going some where wrong.
plz reply me some questions which i had in my mind since long...
Users browsing this forum: No registered users and 1 guest