• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading only one char from user input

 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i'm new to j2me, i have a simple question. I read about High-User interface and low user interface and found no solution to get only one char from the user input. for example: is it possible to get 'b', if the button '2' was pressed twice? do i have to use a Form? Can i use a form without showing the form?

Thanks and sorry for my poor english
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya Kay,

You have a few options:

1. You could use a textbox and set the maxSize of it to 1, so the user can only enter one charachter or digit.
2. You could use a Form containing a TextField, and change it's properties similarly to get one charachter or digit from the user.

But those will both be displayed on the screen. If you want to do it without the user seeing what's going on, you could...

3. Use a Canvas, utilising it's KeyPressed(int keyCode) method that detects when a key has been pressed. Canvas is a bit more difficult to use, but gives you loads of control.

Cheers,
James
 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, i did it like 3.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic