Click to See Complete Forum and Search --> : Ascii


Ingela
January 12th, 2001, 09:46 PM
Hi,

When I click the enter key on my keyboard I would like an URL (a string from an textfield called text) to appear. I know I may use the \n character to see what has happened, but it doesn't work.

I would be even more happy if someone helped me to do this but with the asciicode instead (I tried a little, but now its an comment as you can see), just for learning.

Itworks when I use a button to get the homepage, yes it is an browser I am making.


Thankful for help...

/Ingela
public class EnterListener extends KeyAdapter{
public void KeyTyped(KeyEvent eve) {
try{
char ent = eve.getKeyChar();
if (ent == '\n'){
//char c = '\u0015';
System.out.println(" Testing in EnterListener:);
//String urlen = text.getText();



//String urlen = text.getText();
}
setCursor(Cursor.getDefaultCursor());
//jep.setPage(urlen);

}catch (Exception e){System.out.println(e);}

}
}//end class EnterListener

PSManju
January 13th, 2001, 01:55 AM
check for VK_ENTER in keyPressed. I think this will help u

Ingela
January 13th, 2001, 08:00 AM
Hi P S,

I've tried that one, but Im not sure of the syntax, so maybe I've done something wrong there. Would you please have a look?

Anyway is it better to use VK_ENTER than the other way I asked about before?!

Thanks in advance

/Ingela


public class EnterListener extends KeyAdapter{
public void KeyTyped(KeyEvent eve) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try{

int keycode = eve.getKeyCode();
if (keycode == VK_ENTER){
String urlen = text.getText();
}

}catch (Exception e){System.out.println(e);}

}
}//end class EnterListener

poochi
January 13th, 2001, 01:36 PM
In keyTyped event, Keycode is always 0. I dont know the reason. I think keyTyped() receives
keyevent with lots of bugs. Instead of receiving VK_ENTER it receives carriage return character.
( keycode = 13 )

Why dont you try your code with keyPressed event(method) ?


public class EnterListener extends KeyAdapter{
void keyPressed(java.awt.event.KeyEvent event) {
if( event.getKeyChar() == java.awt.event.KeyEvent.VK_ENTER ){
System.out.println( "Enter key");
}else{
System.out.println( "Not an Enter");
}
}
}

Ingela
January 14th, 2001, 04:31 PM
Now it works fine... thank you, keyPressed was a lot more better. Is this going to work at any computer with any platform, or how does this VK_ENTER thing works?

/Ingela

dlorde
January 15th, 2001, 07:05 AM
"Key pressed" and "key released" events are lower-level than "key typed" events and depend on the platform and keyboard layout. "Key typed" events are higher-level and generally do not depend on the platform or keyboard layout. They are generated when a character is entered, and are the preferred way to find out about character input.

For complete documentation about these differences, see http://www.java.sun.com/products/jdk/1.2/docs/api/index.html).

Dave

To email me remove '_spamjam' from my email address