File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes Putting components in MIDP 2.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Putting components in MIDP 2.0" Watch "Putting components in MIDP 2.0" New topic
Author

Putting components in MIDP 2.0

Bilal Sallakh
Ranch Hand

Joined: Feb 26, 2005
Posts: 45
Hi all, I'm new to the nice world of J2ME.

I'm working with MIDP 2.0 on a P900 Sony-Ericsson simulator using Borland JBuilder.

My program is a simple character recognizer.

I want to display three things on the screen.

1- an area where the user draws the shape.
2- a TextField where the program shows the result.
3- a button (or menu) to go to programs' options.

I used a GameCanvas as a drawing area, and overrided the pointerPressed pointerDragged pointerReleased methods so to draw the trace of the pen.

But I've problems putting other component beside the GameCanvas in the same time.

Uptil now I have:

public class DrawingCanvas extends GameCanvas implements CommandListener {
DrawingCanvas() {super(false);}
protected void pointerPressed(int x, int y) {...}
protected void pointerReleased(int x, int y) {
getGraphics().drawLine(....);
}
protected void pointerDragged(int x, int y) {...}
public void commandAction(Command command, Displayable displayable) {}
}


public class HWRlet extends MIDlet {

protected void startApp() throws MIDletStateChangeException {
DrawingCanvas canv = new DrawingCanvas();
can.addCommand(new Command("Exit", Command.EXIT, 0));
Display.getDisplay(this).setCurrent(canv);
}

protected void pauseApp() {}
protected void destroyApp(boolean _boolean) throws MIDletStateChangeException {}
}


I tried to use a form:

Form fr = new Form("Recognizer Form");
Display.getDisplay(this).setCurrent(can);
fr.append(new TextField);
// fr.append(canv);

But it doesn't work (since append doesn't take a Canvas parameter).

What should I do in order to display them togother?

I tried to use a CustomItem instead of GameCanvas but it doesn't contain the getGraphics() method neccessary for drawing the pen's trace.

Do anyone has an idea?

Thanks in Advance.


SCJP for J2SE 5.0 (beta)<br />SCJA (beta)
Yuri Magrisso
Ranch Hand

Joined: Sep 13, 2003
Posts: 58
In MIDP the GUI components can be divided into 'Screen' components and 'Item' compontents. The 'Screen' components take up the whole screen of the device and they cannot be added to other 'Screen' components. GameCanvas and Form are two screen components and you cannot add GameCanvas to Form. Only 'Item' compontents can be added to a Form.

CustomItem provides a method 'paint(Graphics g)', which is called every time the component has to be repainted. In this method you can draw the pen's trace.

--------------
Yuri
Bilal Sallakh
Ranch Hand

Joined: Feb 26, 2005
Posts: 45
Thank you very much Yuri.

I'm using the CustomItem but it has one (annoying) limitation as you said: One can't draw except in the paint(Graphics g), so there is no getGraphics() as in GameCanvas. I tried to go around it by keeping a reference to the Graphics object I obrain in paint(Graphics g) to use it outside, but as I expected, it just failed (No back-doors in J2ME). The problem is that I do need to draw the whole pen trajectory just to add a new segment so instead of an O(n) I'm forced to have O(n2)...
Do anyone knows about a better berformence (even using external libraries but MIDP-2.0-compantible)? kAWT and kjava seems to target the PalmOS! I'm using te Sony-Ericsson-P900 as an emulator (Mobile devices tend to be less powerful than PDAs)...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Putting components in MIDP 2.0
 
Similar Threads
javax.microedition.io.ConnectionNotFoundException: TCP open
Creation and Event linkage (JavaME CLDC 1.1 MIDP 2.0)
need help!please - something to with canvas. .
problem with double operations
MIDlet cann't connect to servlet on website