Sign in to follow this  
benryves

(MIDP1.0) - Adding soft keys to class extending Canvas

Recommended Posts

benryves    1999
I'm working on a game, Crates3D, for my cellphone. I've got a basic menu working for the main intro bit using a form (It shows a title pic and has a menu with two items: new game and about). However, when I go to the main game I'm in a class called GameScreen which extends Canvas for all it's graphical goodness. How can I populate the white space at the bottom of the screen with softkey buttons? I tried just creating a form but I get all sorts of weird and wonderful errors, and when I tried to create a form with a canvas in another class that extended MIDlet it brought up "Canvas is abstract and couldn't be instantiated". Help!

Share this post


Link to post
Share on other sites
shmoove    821
You can just add Commands to the Canvas subclass:

public class GameScreen extends Canvas implements CommandListener {

// ...

Command menu = new Command("Menu",Command.SCREEN,1);
Command quit = new Command("Quit",Command.EXIT,1);

public GameScreen(...) {
addCommand(menu);
addCommand(quit);
setCommandListener(this);
// ...
}

// ...

public void commandAction(Command c, Displayable d) {
if (c == menu) {
goToMenu();
}
else if (c == quit) {
quitGame();
}
}
}




You don't have to implement the CommandListener in GameScreen either. Some people prefer to have their Command handling centralized in one class, so you could just set the CommandListener to that class instead.

shmoove

Share this post


Link to post
Share on other sites
benryves    1999
Ah, that makes a bit more sense.
I was trying to add commands to a menu.
The whole concept of Classes is still a bit new to me (having come through BBC BASIC, VB6, QB, z80 Assembler) and so I'm finding things a little tricky :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this