|
Author |
Topic: Passing RIGHT and LEFT (Read 447 times) |
|
skloopy
|
Passing RIGHT and LEFT
« on: Dec 5th, 2003, 5:48am » |
|
I'm writing a simple typewriter class, and i want to be able to pass the RIGHT and LEFT keys to it so I can change the cursor postion, but as soon as I pass the "key" variable RIGHT and LEFT don't work anymore.. Anybody know what i'm doing wrong? Code:class Typewriter { String buffer = ""; int insert = 0; Typewriter() {} void type(int c) { switch(c){ case 8: delete(); break; //case RIGHT: if(insert > 0) insert--; break; //case LEFT: if(insert < buffer.length()) insert++; break; case 13: // Avoid special keys case 65535: case 127: case 27: break; default: buffer = buffer+(char)c; break; } } void type(String s) { buffer = buffer+s; } void delete() { if(buffer.length() > 0) { buffer = buffer.substring(0,buffer.length()-1); } } } |
| Thanks!
|
|
|
|
Andreas Guest
|
Re: Passing RIGHT and LEFT
« Reply #1 on: Dec 5th, 2003, 10:26am » |
|
You have the Variable c as an int. You switch c. So c can't never be RIGTH or LEFT cause it's an int.
|
|
|
|
skloopy
|
Re: Passing RIGHT and LEFT
« Reply #2 on: Dec 5th, 2003, 8:11pm » |
|
So are RIGHT and LEFT constants for chars then? If they're chars shouldn't they be castable to ints? Sorry if this is obvious
|
« Last Edit: Dec 5th, 2003, 8:15pm by skloopy » |
|
|
|
|
skloopy
|
Re: Passing RIGHT and LEFT
« Reply #4 on: Dec 8th, 2003, 11:40pm » |
|
Okay. i figured it out. It turns out that RIGHT and LEFT and all will work fine if you're using keyPressed, but I was using keyTyped, since it's a typewriter. I guess they just don't register in keyTyped.. Fry, is that intentional?
|
|
|
|
fry
|
Re: Passing RIGHT and LEFT
« Reply #5 on: Dec 9th, 2003, 7:53pm » |
|
yeah, seems that sun handles the key codes differently for when it's keyTyped or keyPressed, so i need to modify things to work around that. so, i'll move this over to bugs. should be an easy fix.
|
|
|
|
|