• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

keyPressed() and TextBox

 
Benjoe Reyes
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible that i could use keyPressed() to get the input and put the input in a textbox instead of painting it in the Canvas?
 
Sathya Srinivasan
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not directly possible because of the way MIDP API is setup.
MIDP API is split into two parts - High-level API and Low-Level API.
High-Level API abstracts all the event handling details and gives you general methods. All classes under Screen fall under this category (hence TextBox)
Low-Level API is more open and lets you handle events. Classes under Canvas fall under this category.
Since TextBox is a High-Level API, you cannot access a low-level API.
Hope this helps.
 
Benjoe Reyes
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i'm stuck with the drawChar() in Canvas is that so?
however you said directly my premise is not possible but how about indirectly? could i just call a method inside keyPressed() that would do the TextBox thing?
it is said (wrox Professional Java Mobile Programming ch5 p.176) we can mix a Canvas and a Screen in a single application.Just don't mix both high and low level in one single Screen. So the low level would be the keyPressed part and the high level would be the TextBox. i just don't know to go about it. Since Display.setCurrent would only accept 1 displayable.
 
Jason Fox
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do something like drawing your own 'textbox' using your canvas' paint() method to do the drawing and then use the keyPressed() method to
to repaint the screen, adding or removing the appropriate characters from your 'textbox'.
Jason
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic