(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
05-17-24 10:51 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - [Java] This looks right, but... New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
neotransotaku

Sledge Brother
Liberated from school...until MLK day








Since: 11-17-05
From: In Hearst Field Annex...

Last post: 6300 days
Last view: 6298 days
Posted on 12-19-05 10:20 PM Link | Quote
it doesn't do what I intended

  public void keyPressed(KeyEvent e)

{
switch(e.getKeyChar())
{
case(KeyEvent.VK_CAPS_LOCK):
switch(typeMode)
{
case(MODE_ASCII):
typeMode = MODE_JPN;

break;
case(MODE_JPN):
typeMode = MODE_ASCII;
break;
default:
throw new IllegalArgumentException("Invalid TypeMode");
}
break;
default:
System.out.println(KeyEvent.getKeyText(e.getKeyChar()));
}
}


this code always lands me in default when I press Caps Lock...

side note--if anyone knows how to disable br's inside pre with CSS, PM me with code, thanks.
Euclid



 





Since: 11-17-05
From: Australia
hmm...

Last post: 6304 days
Last view: 6298 days
Posted on 12-19-05 10:50 PM Link | Quote
It looks right... assuming you did set a default value for typeMode (ascii or jpn) in some constructor before running that code.

The 2 mode variables seems to be man-made (static final ints?), i have no idea what type they are or if they're comparable, why don't you try an if statement instead and see if that works properly, and also try outputing the type of the variable before throwing an exception, that might help knowing why it has jumped to the default.
Squash Monster

Bouncy


 





Since: 11-18-05
From: Right next to myself.

Last post: 6306 days
Last view: 6299 days
Posted on 12-20-05 08:06 PM Link | Quote
If the mode variables are ints, like Euclid guessed, then this code should work fine. If they're Strings or anything else you can't accurately use == with, then there's going to be a problem.

Or there could be a problem elsewhere in the program. Putting something like this in your default statement might bring something to light:

System.out.println(typeMode + " : " + (typeMode == MODE_ASCII) + " : " + (typeMode == MODE_JPN));
neotransotaku

Sledge Brother
Liberated from school...until MLK day








Since: 11-17-05
From: In Hearst Field Annex...

Last post: 6300 days
Last view: 6298 days
Posted on 12-21-05 01:45 AM Link | Quote
ack...i wasn't clear which default I was in.

The problem is the code thinks the caps lock key is not pressed, even when I am pressing the damn key. So...any ideas of how to get this code to recognize when caps lock is pressed. I also have a keyTyped function in the same class and it recognizes my keystrokes (so that rules out the fact that I have not added my listener). MODE_ASCII and MODE_JPN are static final ints and typeMode is initialized to MODE_ASCII
Euclid



 





Since: 11-17-05
From: Australia
hmm...

Last post: 6304 days
Last view: 6298 days
Posted on 12-21-05 02:08 AM Link | Quote
Maybe it's your keyboard, try to find out the value for vk_caps_lock (i think it defaults to 0x20 for most cases) and the actual caps lock value on your comp, you might have to do some hardcoding...
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6298 days
Last view: 6298 days
Posted on 12-23-05 11:09 AM Link | Quote
It could just not be passing the Caps Lock key to the listener... add something to print the value of every key pressed, then hit Caps Lock a few times. If nothing gets printed, then you need to find another way to see when it's pressed.
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - [Java] This looks right, but... |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.008 seconds; used 373.24 kB (max 454.73 kB)