IntelliJ Java IDE
The moose likes Applets and the fly likes Applets Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Applets
Reply Bookmark "Applets" Watch "Applets" New topic
Author

Applets

mnsvPrasad
Greenhorn

Joined: Feb 16, 2001
Posts: 7
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

Joined: Sep 29, 2000
Posts: 8521
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.


"JavaRanch, where the deer and the Certified play" - David O'Meara
mnsvPrasad
Greenhorn

Joined: Feb 16, 2001
Posts: 7
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

Joined: Jun 14, 2000
Posts: 347
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

Joined: Feb 16, 2001
Posts: 7
Thank You very much for your help.
mnsvPrasad
Greenhorn

Joined: Feb 16, 2001
Posts: 7
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

Joined: Jun 14, 2000
Posts: 347
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
 
 
subject: Applets
 
Threads others viewed
thanks!!! another SCJP born~
Args in Netbeans
Ant and Cactus - classpath issues
http-method not specified
Clock problem
developer file tools