J2ME - Textfield on Canvas

S

Stefan Reiter

Hi, I would like to have a nicely designed page with
a Textfield on it.

If I just create a class that extens Form,
I can't access the graphics stuff,
and if I extend the Canvas Class I don't see a way how
to add a textfield.

I found some examples on textfield and some on how to extend Canvas,
but they never explain how to get a canvas with a textfield.

Any ideas?

Thanks,

Stefan
 
D

Darryl Pierce

Stefan said:
Hi, I would like to have a nicely designed page with
a Textfield on it.

If I just create a class that extens Form,
I can't access the graphics stuff,
and if I extend the Canvas Class I don't see a way how
to add a textfield.

That's because you *can't* add any of the Item classes (TextField,
StringItem, ImageItem, etc.) to a Canvas. The Canvas is part of the
low-level UI classes, TextField a part of the hi-level UI classes, and
you can't mix them together on a single screen.
 
S

Stefan Reiter

What alternatives do I have?

couldn't I acess the Graphics Object in my form,
or maybe there is some custom code example,
where someone created their own textfield with design features,

or another idea I had was to have a screen with a sprite for each
letter, and then the user can select letter by letter to type in his
name. ( Used to add his name to a highscore list).
Maybe someone has sample code for this?

I am developing a little game, and it would be a shame to have a nice
looking game, but when the user enters his name for the highscore list
an ugly looking white page pops up.

Any ideas?

Thanks,

Stefan
 
T

Tor Iver Wilhelmsen

Stefan Reiter said:
If I just create a class that extens Form,

What's "Form"?
I can't access the graphics stuff, and if I extend the Canvas Class
I don't see a way how to add a textfield.

Why not use one of the containers, like Panel? Subclassing should only
be done when you absolutely have to, prefer instead to use
composition.

(As an aside: The assembling of AWT or Swing components is an example
of the buzzword du jour, IOC, so if someone asks if you know Inversion
of Control and you have assembled a Swing app (including event wiring)
you can answer "yes".)
 
D

Darryl Pierce

Stefan said:
What alternatives do I have?

couldn't I acess the Graphics Object in my form,
or maybe there is some custom code example,
where someone created their own textfield with design features,

You can't access the low level aspects of the hi-level UI objects. The
rendering of all of the hi-level UI objects is out of reach.
or another idea I had was to have a screen with a sprite for each
letter, and then the user can select letter by letter to type in his
name. ( Used to add his name to a highscore list).
Maybe someone has sample code for this?

Take a look at the Open Windowing Toolkit on, I believe, Sourceforge.
There's a whole replacement UI toolkit for MIDP applications. But, keep
in mind you're sacrificing both speed and application space to create
the UI. And, you're not conforming to the device itself. Studies have
shown that users prefer an application on their phone behave like all
other applications on their phone than to have some unique or gimmicky
interface.
I am developing a little game, and it would be a shame to have a nice
looking game, but when the user enters his name for the highscore list
an ugly looking white page pops up.

You can write your own TextField widget.
 
D

Darryl Pierce

Tor said:
What's "Form"?

javax.microedition.lcdui.Form is a part of the MIDP specification.
Why not use one of the containers, like Panel? Subclassing should only
be done when you absolutely have to, prefer instead to use
composition.

He's working in the MIDP, which has neither AWT nor Swing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top