Register | Login | |||||
Main
| Memberlist
| Active users
| ACS
| Commons
| Calendar
| Online users Ranks | FAQ | Color Chart | Photo album | IRC Chat |
| |
0 user currently in Programming. | 3 guests |
Acmlm's Board - I2 Archive - Programming - Java KeyListeners | | | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
User | Post | ||
Squash Monster New Age Retro Hippie Togateiru Fohku Kohgeki!! GRUNGE no HAMSTER otona bite Peace love and turnpike! Level: 40 Posts: 491/677 EXP: 430507 For next: 10802 Since: 03-15-04 From: Maryland (of the Country Between Canada and Mexico) Since last post: 5 hours Last activity: 5 hours |
| ||
I managed to get the graphics to redraw in my game (switched to JPanel instead of Applet). Here's a slightly out-dated screenshot (drag to adress bar or copy/paste) http://squashmonster.tripod.com/Treasure/treasureGameSS2.png Now I'm trying to read keyboard input to controll the character. I can't figure out what I'm doing wrong though. Some excerpts from my code: Stepper.java KeyboardIn.java You'll notice that my KeyboardIn class is set to print the System screen whenever anything happens. It never does though. How did I mess up? Am I using the wrong class? |
|||
neotransotaku Baby Mario 戻れたら、 誰も気が付く Level: 87 Posts: 1928/4016 EXP: 6220548 For next: 172226 Since: 03-15-04 From: Outside of Time/Space Since last post: 11 hours Last activity: 1 hour |
| ||
is your JPanel surrounded by any derivative Frame class? if so, the JPanel will never see any keys... | |||
HellSavior Red Goomba Level: 12 Posts: 14/41 EXP: 6398 For next: 1523 Since: 03-18-04 Since last post: 212 days Last activity: 110 days |
| ||
It would be more efficient to do something like this : class Stepper extends JPanel implements KeyListener { ... public Stepper { setFocusable(true); requestFocusInWindow(); addKeyListener(this); } public void keyPressed(KeyEvent e) { switch(e.getKeyCode()) { case KeyEvent.VK_LEFT: sendTo.takeKey(1); break; ... } } } There are a few more methods you have to implement from KeyListener, but I cannot remember them off the top of my head. EDIT : It does not seem that this board likes spaces. Messy code it is.. (edited by HellSavior on 12-29-04 07:09 AM) |
|||
Squash Monster New Age Retro Hippie Togateiru Fohku Kohgeki!! GRUNGE no HAMSTER otona bite Peace love and turnpike! Level: 40 Posts: 496/677 EXP: 430507 For next: 10802 Since: 03-15-04 From: Maryland (of the Country Between Canada and Mexico) Since last post: 5 hours Last activity: 5 hours |
| ||
That's an interesting solution, though I've already got a working one now. I'll remember your version though, it should be usefull for some other projects. Thanks. |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
Acmlm's Board - I2 Archive - Programming - Java KeyListeners | | | |