July 1, 2008

About middlet and gamecanvas

Midlet

When you start to programming with java for mobile ,first class you build is midlet .Midlet is an interface between you and mobile. In netbeans you can easily add midlet automatically or with right click in project and in new menu click in visual midlet. In visual midlet you have a form by default and actions belong to it and in graphical interface you can easily add text or other thing to form but if you dont wnat to have form in your program you need only midlet.This class have functions like startApp,destoryApp,startMidlet and like .This function say's what you want to do when midlet started or your program started and etc.In middle you can also switch display of your program between graphics and forms that you make or add your command to your program. It is better that you have this class and game canvas and game engine in different file. It give your program better readability and of course better performance.You can use your game engine in other programs and your game canvas in other midlet and many other features.

Your game engine can also contains more class in base you programs.

__________________________________________________________________________________

Gamecanvas

In mobile programs you have also a gamecanvas (midpcanvas) class.This class contain function for pressing or dragging or clicking keys or pointers and you can add your functions to them.it is an example

protected void keyPressed(int keyCode) {

int action = getGameAction( key );

switch(action)

{

Case DOWN:

MOVEDOWN();

.

.

.
}

}

DOWN,UP,RIGHT,LEFT are predefined value's in gamecanvas class and their value is same with returning value from getGameAction(key) when you click down ,up,right and left key in mobile.

A game canvas also has paint function .With paint and repaint function you can draw your graphic world(you'll learn about it in following posts) .You can change your graphics world everywhere and repaint it everywhere also.But you should know more repaint in bad place in class forced to some problem in your game graphics .

With this primary information you are almost ready for start programming .

Read more »