Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Nikola Veber - 26 Jun 2005 15:14 GMT
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
Jakob Bieling - 26 Jun 2005 15:34 GMT
> 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!
Signature

jb

(reply address in rot13, unscramble first)

Nikola Veber - 26 Jun 2005 15:45 GMT
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)

>>I'm making a game in j2me, that should be midp1.0 compatabile. The
>>thing
[quoted text clipped - 10 lines]
>
> hth!
Jakob Bieling - 26 Jun 2005 15:48 GMT
> 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
Signature

jb

(reply address in rot13, unscramble first)

Nikola Veber - 26 Jun 2005 15:58 GMT
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

>>I'm aiming for fancy graph. fonts, background image and so on...
>>
[quoted text clipped - 12 lines]
>
> regards
Jakob Bieling - 26 Jun 2005 16:41 GMT
> 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
Signature

jb

(reply address in rot13, unscramble first)

Jakob Bieling - 26 Jun 2005 16:47 GMT
>    Well, I am sort of using that. First, if I have a known phone, [..]

   and if I don't, I fall back to getGameAction .. just to complete the
sentence ;)
Signature

jb

(reply address in rot13, unscramble first)

Darryl Pierce - 26 Jun 2005 16:50 GMT
>     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
[quoted text clipped - 5 lines]
> 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".

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard

Jakob Bieling - 26 Jun 2005 17:05 GMT
>> [..] 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
Signature

jb

(reply address in rot13, unscramble first)

Darryl Pierce - 28 Jun 2005 00:45 GMT
>>Why are you doing that? The implementation should be passing the
>>keycode to Canvas.keyPressed as an int which will convert to an
[quoted text clipped - 8 lines]
> 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.

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard

Jakob Bieling - 28 Jun 2005 06:23 GMT
>>>Why are you doing that? The implementation should be passing the
>>>keycode to Canvas.keyPressed as an int which will convert to an
[quoted text clipped - 13 lines]
> 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
Signature

jb

(reply address in rot13, unscramble first)

Nikola Veber - 26 Jun 2005 18:35 GMT
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 ?

>>     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
[quoted text clipped - 12 lines]
> character and not just the last one pressed being advanced; i.e., "ab"
> and not just "b".
Jakob Bieling - 26 Jun 2005 18:46 GMT
[top posting rearranged]

>> [..] 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
Signature

jb

(reply address in rot13, unscramble first)

Nikola Veber - 26 Jun 2005 18:59 GMT
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 !

> [top posting rearranged]
>
[quoted text clipped - 15 lines]
>
> regards
Darryl Pierce - 26 Jun 2005 16:48 GMT
> 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.

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard

Darryl Pierce - 26 Jun 2005 16:47 GMT
> 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.

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.