[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
J2MEFAQ_HowDoIDoGraphics

J2MEFAQ How Do I Do Graphics

In J2ME development there are several different graphics APis depending upon which Profile you are targeting for development. While the main coverage will be the MIDP Profile graphics apis we will also give a brief overview of graphics in other profiles such as PersonalProfile.

MIDP Low Level Graphics

Low Level Graphics is often used in games due to the control you get over pixels. Low Level graphic interfaces are constructed using canvas objects. For example:

import javax.microedition.lcdui.*;
class CanvasDo extends Canvas {
      protected void paint(Graphics g) {
      g.fillRect(20,30,30,20);
    }
}


Using this inside a midlet displays a simple rectangle. To display any graphics object you must grab a displayble object then set that boject as the canvas, such as:

Display d;
d= Display.getDisplay(this);
d.setCurrent(CanvasDo);


MIDP High Level Graphics

High level graphics in MIDP comes in two types of Screen subclasses. The first type of Screens are List, TextBox, and Alert. You cannot add other graphical elements to this type of Screen objects. An example might look like this:

textbox = new TextBox("", "Hi there", 20, 0);






The other type of screen object is a form which can containother graphical elements such as text, images, and etc. While the midlet might look like this:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class FormDo extends Midlet {
    Display d;
    Form aForm;
    public FromDo () {
      aForm = new Form("I am aForm");
    }
    protected void startApp() {
       d= Display.getDisplay(this);
       d.setCurrent(aForm);
    }
    protected void pauseApp() {
    }
    protected void destroyApp(boolean uncoditional) {
    }
}


The From constructor code then of course places the other graphical elements on the form.

NON MIDP Graphics

On higher end J2ME one is simply using light versions fo AWT in most cases. The same AWT found in JDK 1.1.8 or PersonalJava. The only difference is that in this light version of AWT only one JTable container can exist at any one time as the root container.

last edited (March 12, 2004) by BadAttitude, Number of views: 3548, Current Rev: 6 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.