Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applets

 
mnsvPrasad
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. How a javaScript Functions such as alert() can be used in the Applet?
2. How to Nullify the invalid Key Code, and in which event it has to set?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript has nothing to do with Java. They are unrelated.
If you want to ignore a particular key, you need to create an Key Listener and listen for the KeyEvent of the particular key you are interested in (key pressed), then you can capture the input and get rid of it.
If you look up KeyEvent in the API, under the see also: heading they have a link to a tutorial on how to set up a key listener.
 
mnsvPrasad
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response.
I have tried using Key Listener interface.I wrote code in the
KeyPressed Event. I checked for the keyChar and if it was not a valid char i assigned CHAR_UNDEFINED using setKeyChar.But still the char is getting printed in the textbox.
Can you help further?
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you are trying to prevent the user from entering certain characters. If the user types the invalid character, you do not even want it to show up in the TextField. Below is a brief example of this. It prevents the user from typing a '.' in the TextField:

Cindy's suggestion is very good. I also think the tutorial will help you.
Next time, please be sure to register with a proper name. "mnsvPrasad" does not follow the conventions. See here for details: http://www.javaranch.com/name.jsp
If you do not register properly, your account will be disabled. I would hate to see that happen.
Thank you.
Stephanie
 
mnsvPrasad
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You very much for your help.
 
mnsvPrasad
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for resopnding and also for sending a sample.
But i have seen my API i can't fine KeyEevent.consume(), i found
KeyEevent.consumed() if it is a method of the new version of the JAVA i am using 1.2.2 API.
Please respond
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The consume() method is a member of the base class of KeyEvent, java.awt.event.InputEvent.
Hope this helps.
Please do not forget to register with a proper name.
Stephanie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic