Saturday, January 16, 2010

Basic Java ME Game Template

Jump to part: 1 | 2 | 3

The last tutorial showed you how to use Netbeans IDE to create a basic Java ME MIDlet, compile it, and preview your program in the emulator. Unfortunately, the code generated for the Hello MIDlet is not really suitable for making games that require constant screen updates and lots of animation or movement. This tutorial will show a simple framework that allows you to use lower level drawing functions for making games. The steps that will be taken are as follows:
  • Create an empty Java ME - Mobile Application project.
  • Create the main MIDlet.
  • Create a clsCanvas class which extends the GameCanvas class and implements the Runnable interface.
  • Create the main game loop which will contain all the drawing routines.
  • Launch a worker thread to start and run the main game loop.

Creating the Mobile Application project
First off, open Netbeans IDE and press CTRL+SHIFT+N to create a new project. Choose "Java ME" from the "Categories" list and "Mobile Application" from "Projects" list then click on the "Next" button.

New Project wizard

Change the project name to "myGame". What we need is an empty or blank project so rememeber to uncheck the "Create Hello MIDlet" option before clicking on the "Next" button.

Name and Location screen

On the "Default Platform Selection" screen, choose "DefaultCldsPhone1" for the "Device". Choose "CLDC-1.0" for the "Device Confirguration". Finally, choose "MIDP-2.0" for the "Device Profile" then click on the "Finish" button.

Default Platform Selection screen

You should now be looking at something like this:

The empty project

Creating the Midlet
Now we need to create the MIDlet ourselves. There are several ways to go about this.
  • By pressing CTRL+N on your keyboard.
  • By choosing "New File" from the "File Menu".

  • By right-clicking on the project panel treeview and selecting the "New" item, then clicking on "MIDlet".

For those of you who used one of the first two ways, select "MIDP" from the list of categories and "MIDlet" from the list of file types then click on the "Next" button.

New File wizard

On the "Name and Location" screen, type in "midMain" for "MIDlet Name". The "MIDlet Class Name" field will be automatically filled in for you. Leave the "MIDlet Icon" blank for now. As a rule of thumb, never create your files in the "default package". Enter "pkgGame" in the "Package" field. Click on the "Finish" button.

Name and Location screen

A folder with the same name as the package name you previously entered will be created inside the project source folder where all source code for your game should go.

MIDlet source code

Congratulations!! You have succeeded on creating an empty MIDlet that does absolutely nothing. Next stop, Creating the Canvas...


Car Dvd said...

Nice Post
Best Car Double Din

Unknown said...

This is a wonderful post.thanks for sharing free pet catalogs by mail

Mehmood Ali said...

I have perused your article, it is exceptionally instructive and accommodating for me.I appreciate the significant data you offer in your articles. Much obliged for posting it..
Enhancing The Effectiveness Of Application Development

agwet said...

An intriguing discussion is worth comment. I think that you ought to publish more on this subject matter, it might not be a taboo matter but generally people don't discuss these issues. To the next! Kind regards! How to get Live psl streaming ?

Unknown said...

keto trim diet plan
“I’ve gained a few of my weight back again because of letting myself have cheats here and there - especially during the holidays and being with friends and family! Right now, I’m going back to keto basics, and losing the weight that I had gained and, hopefully, I’ll be much more successful this time around,” Lele explains.

mohammed ababneh said...

Thanks for the great post

Logan Jack said...

I just couldn’t depart your site prior to suggesting that I extremely enjoyed the standard information an individual provide for your visitors? Is gonna be back frequently in order to inspect new posts iphone photoshop

Yousufzai said...

I am still learning of your stuff, and i am attempting to achieve my objectives. I completely adore reading through all that is written in your website. Maintain the actual ideas arriving for long term ! Thanks ! iphone device template

khanabaaz said...

Yay google is my world beater helped me to find this great web site ! . ipad mockups

Unknown said...

Basically to follow up on the up-date of this topic on your web site and wish to let you know simply how much I loved the time you took to generate this valuable post. Within the post, you really spoke of how to actually handle this matter with all ease. It would be my pleasure to collect some more ideas from your web page and come as much as offer other people what I learned from you. Many thanks for your usual terrific effort. android mockup psd

Anjali Vinu said...

Outstanding blog with lots of information. Keep posting more like this.
Blue Prism Training in Chennai
Blue Prism Training Chennai
RPA Training in Chennai
Robotics Process Automation Training in Chennai
RPA course in Chennai
UiPath Training in Chennai
Automation Anywhere Training in Chennai
Machine Learning course in Chennai
Machine Learning Training in Chennai
PHP Training in Chennai
Future of Blue Prism

Unknown said...

You seem to be very professional in the way you write.::’~* top web development companies

Ava Alba said...

Actually I read it yesterday but I had some ideas about it and today I wanted to read it again because it is so well written.

I already bookmarked your site to check out the new stuff you post.

It’s hard to find high-quality writing like yours these days. I honestly appreciate individuals like you! Take care!!

I also have a blog.

Best Photoshop Tutorials

Don't forget to check it. Thank you.

Aj Digital Marketing said...

Nice to see your content. You are sharing such a great info.
Want to know about best ways to say happy birthday? Just go on our website

Birthday Wishes For All
Birthday Wishes For Friends
Birthday Wishes For Mother
Birthday Wishes For Elders
Birthday Wishes For Father
Birthday Wishes For Husband
Birthday Wishes For Wife

Unknown said...

Looking for Website Development Packages in India? You are at right place. We are able to help you with website development, designing, and web designing services.