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

AWT

 
Srinivasan Keshavamurthy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am having a problem in setting uppercase characters to a textfield in an applet in both the browsers (IE5.5 and Netscape 4.72). I am using jdk1.1.8.
I have the following piece of code in my keyTyped method :
((KeyEvent)evt).setKeyChar(Character.toUpperCase(((KeyEvent)evt).getKeyChar()));
This executes fine in Netscape but fails in IE. On the other hand if the same piece of code is put inside keyPressed, it works in IE but fails in Netscape.
Any suggestions on this will be of great help.
Thanks in advance
Srinivasan Keshavamurthy
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not put it in both methods? That way it will work no matter what browser you are using...

It sounds like there are differences in the way the IE VM and the Netscape VM handle KeyEvents...

-Nate

P.S. - This is really more suited for the Applets forum, and some people over there may be able to help you more, so I'm moving it there...
 
Srinivasan Keshavamurthy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I did try putting in both the keyTyped and keyPressed methods but, that worked in IE but failed in Netscape.
I got a solution to it but unable to find an explanation for it. I will explain in detail:
The code previously was like this:
switch(event.getID()){
case KEY_TYPED:
((KeyEvent)evt).setKeyChar (Character.toUpperCase(((KeyEvent)evt).getKeyChar()));
case SOME_OTHER_EVENT:
// CODE
}
What i did was to check for the event outside switch which was something like this:
if (evt.getID() == KeyEvent.KEY_TYPED) {
((KeyEvent)evt).setKeyChar(Character.toUpperCase (((KeyEvent)evt).getKeyChar()));
}
switch (event.getID()){
case SOME_OTHER_EVENT:
// CODE....
}
and it worked !
But i am unable to see the difference in both the codes.
Any guesses as to what's happening.
Thanks
Srinivasan keshavamurthy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic