Posts

Showing posts from September, 2008

J2ME,GameCanvas and Thread

Image
And here is the GameCanvas class package MyApp; import java.io.IOException; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; import java.lang.Runnable.*; public class MyGameCanvas extends GameCanvas implements Runnable { private boolean vRenderLoop; private int vXPos; private int vWidth; private int vHeight; MyGameCanvas() { super(true); System.out.println("Constructor called"); vXPos=0; vWidth=getWidth(); vHeight=getHeight(); vRenderLoop=false; } public void paint(Graphics g) { } public void start() { System.out.println("start invoked"); vRenderLoop=true; Thread t = new Thread(this); t.start(); } public void stop() { vRenderLoop=false; } public void render(Graphics g) { g.setColor(0xffffff); g.fillRect(0,0,vWidth,vHeight); vXPos++; g.setColor(0x000000); g.fillRect(vXPos, 50, 100,100); ...

J2ME Canvas with Threading

Image
What we shall do here is the following 1) Create a Midlet 2) Create a Canvas class which implements the threading 3) Load a PNG image 4) Render the image through the thread. Configuration. You would need to download the Netbean IDE. When I did this program the version I had was NetBean IDE 6.1. You can go to their website to download it. It would suite for other programming languages too, including the Set Top Box. The program. The Midlet: Just like an applet for the browser, the midlet is an application running in the mobile platform using J2ME. So to run an application on a mobile device you first need a Midlet class. This is the midlet class. package MyApp; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class MyApp extends MIDlet { public void startApp() { MyGameCanvas myApp = new MyGameCanvas(); myApp.start(); Display.getDisplay(this).setCurrent(d); } } For better understanding I am keeping this class as sm...