J2ME, MIDP1.0 - Text input in low level graphics api (Canvas)

N

Nikola Veber

Hi!

I'm making a game in j2me, that should be midp1.0 compatabile. The thing
is, that I need to let user type some text (name on the highscore screen
etc).

Is there something I could use, or I have to solwe this myself?
(with some sort of timers or smth)


Thanks

Nikola
 
J

Jakob Bieling

I'm making a game in j2me, that should be midp1.0 compatabile. The
thing
is, that I need to let user type some text (name on the highscore
screen
etc).

Have a look at javax.microedition.lcdui.* .. there you will find a
class TextBox (which is a whole Screen) and TextField (which is just an
item to be put on a Form).

Not sure where you can find the docs online, but here they where
installed with Sony Ericsson's J2ME SDK.

hth!
 
N

Nikola Veber

I'm aiming for fancy graph. fonts, background image and so on...

Can I use those elements withiut defining them in a form? (I've used
them with forms before, but not with Canvas)
 
J

Jakob Bieling

Nikola Veber said:
I'm aiming for fancy graph. fonts, background image and so on...

Can I use those elements withiut defining them in a form? (I've used
them with forms before, but not with Canvas)


Then you do will have to roll your own, I'm afraid. The only
annoyance you will encounter, is having to take care of the phone
differences yourself. For example, the space is entered differently on
Nokia and Sony Ericsson phones. I am currently doing something similar
(my own menu on a Canvas, where you will be able to inline-edit part of
the menu item) and also had to create a mapping function, which (based
on the phone type specified by the user) returns the value of the space
key. Maybe you know a better solution to this .. if so, I'd be glad to
hear from you :)

regards
 
N

Nikola Veber

Unfortuanately, no. Maybe one coud play aorund with game_action or
however it was called (forgott), but I don't believe it'll work.
Im doomed to taking care of the models anyway, since I couldn't figure
out how to handle different screen sizes.
Any tipps on that? :)


Cheers

Nikola
 
J

Jakob Bieling

Nikola Veber said:
Unfortuanately, no. Maybe one coud play aorund with game_action or
however it was called (forgott), but I don't believe it'll work.

Well, I am sort of using that. First, if I have a known phone, I
check for the hardcoded keyCodes (for example, -11 is the back key on
K700i) and map that to a more general identifier. Currently, I am
mapping it to GAME_A-D, but I guess that is not such a good idea .. so
maybe I will create my own general key identifiers.
Im doomed to taking care of the models anyway, since I couldn't figure
out how to handle different screen sizes.
Any tipps on that? :)

Well, the Canvas has getWidth and getHeight member functions. They
return the size of the Canvas, so the result will differ, depending on
if you are in fullscreen or not.

regards
 
D

Darryl Pierce

Nikola said:
I'm making a game in j2me, that should be midp1.0 compatabile. The thing
is, that I need to let user type some text (name on the highscore screen
etc).

Is there something I could use, or I have to solwe this myself?
(with some sort of timers or smth)

You can put a TextField into a Form and use that, and it would be very
portable. But, you will not be able to have graphics on the screen or
anything of that sort.

If you want to put an input field into one of your graphical screens,
you will have to roll your own input widget and handle validation,
keycode translations, etc. yourself.
 
D

Darryl Pierce

Nikola said:
I'm aiming for fancy graph. fonts, background image and so on...

Then you will have to write your own widget to do the work.
Can I use those elements withiut defining them in a form? (I've used
them with forms before, but not with Canvas)

No, you can't. Items (TextField, etc.) can only be realized in a Form.
 
D

Darryl Pierce

Jakob said:
Then you do will have to roll your own, I'm afraid. The only
annoyance you will encounter, is having to take care of the phone
differences yourself. For example, the space is entered differently on
Nokia and Sony Ericsson phones. I am currently doing something similar
(my own menu on a Canvas, where you will be able to inline-edit part of
the menu item) and also had to create a mapping function, which (based
on the phone type specified by the user) returns the value of the space
key. Maybe you know a better solution to this .. if so, I'd be glad to
hear from you :)

Why are you doing that? The implementation should be passing the keycode
to Canvas.keyPressed as an int which will convert to an alphanumeric
character depending on the platform. The problem you'll face is how long
to wait between keystrokes to consider the next one to be a new
character and not just the last one pressed being advanced; i.e., "ab"
and not just "b".
 
J

Jakob Bieling

Jakob Bieling wrote:
[..] had to create a mapping function, which (based on the phone type
specified by the user) [..]
Why are you doing that? The implementation should be passing the
keycode to Canvas.keyPressed as an int which will convert to an
alphanumeric character depending on the platform. The problem you'll
face is how long to wait between keystrokes to consider the next one
to be a new character and not just the last one pressed being
advanced; i.e., "ab" and not just "b".

Right, for letters, this is not a problem, as this is standardized.
Problem arises when you want to enter a space. Nokia uses the 0, Siemens
the 1, Sony Ericsson the # key. Other differences include punctuation-,
Umlaut- or other special characters in the French or Spanish alphabet,
as well as the key for switching between Caps and nocaps.

regards
 
N

Nikola Veber

Well, I could do that somehow with running this in a separate thread or
so, I still need to think about it.
Is there anything like that in MIDP 2.0 ?
 
J

Jakob Bieling

[top posting rearranged]

Darryl Pierce wrote:
[..] how long
to wait between keystrokes to consider the next one to be a new
character and not just the last one pressed being advanced; i.e.,
"ab"
and not just "b".
Well, I could do that somehow with running this in a separate thread
or
so, I still need to think about it.
Is there anything like that in MIDP 2.0 ?

An alternative will be to use System.currentTimeMillis () and store
the time the last keystroke occured. So in each call to keyPressed you
know how long it has been since the previous keystroke occured. Saves
you the resources needed for a new thread :)

regards
 
N

Nikola Veber

Thats also an option. I had that one in mind, but not as a clear idea.
Anyway, then I wont be able to have the poiner or somethig thar
resembles one... hope the ones above wont think of it ;)

Thanks !

Jakob said:
[top posting rearranged]


Darryl Pierce wrote:
[..] how long
to wait between keystrokes to consider the next one to be a new
character and not just the last one pressed being advanced; i.e.,
"ab"
and not just "b".

Well, I could do that somehow with running this in a separate thread
or
so, I still need to think about it.
Is there anything like that in MIDP 2.0 ?


An alternative will be to use System.currentTimeMillis () and store
the time the last keystroke occured. So in each call to keyPressed you
know how long it has been since the previous keystroke occured. Saves
you the resources needed for a new thread :)

regards
 
D

Darryl Pierce

Jakob said:
Right, for letters, this is not a problem, as this is standardized.
Problem arises when you want to enter a space. Nokia uses the 0, Siemens
the 1, Sony Ericsson the # key. Other differences include punctuation-,
Umlaut- or other special characters in the French or Spanish alphabet,
as well as the key for switching between Caps and nocaps.

Have you tested this? The handset is supposed to pass to
Canvas.keyPressed the ASCII value for the key pressed, which includes
spaces, etc.
 
J

Jakob Bieling

Darryl Pierce said:
Have you tested this? The handset is supposed to pass to
Canvas.keyPressed the ASCII value for the key pressed, which includes
spaces, etc.


Yes, but instead of passing 32 for the space, it passes the ASCII
codes of the characters on the key (ie. 35 for # etc). Not sure if this
is a unique 'feature' of Sony Ericsson phones, but its enough to make me
use a mapping for the space. I am also mapping the 'Shift' key this way.

While we are at it, there are also softkeys, which I want to use as
well, but: Using Canvas.getGameAction does not return any usable values
for those (always 0). According to the docs, I shall not use the
hardcoded values for those keys, but is exactly what I am doing now.
Otherwise, I see no way of being able to catch those keys. Maybe you
have a better idea tod o this.. ?

regards
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top