Playing around with both right now but it doesn't appear to work. I think I
may be using it in the wrong place? Here's my Canvas constructor code, showing my implementation:
validate() and requestFocus() calls are made at the end of the canvas constructor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| CvWorld(OverworldFrame master) { masterFrame = master;
addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if(key == KeyEvent.VK_UP) up = true; else if(key == KeyEvent.VK_DOWN) down = true; else if(key == KeyEvent.VK_RIGHT) right = true; else if(key == KeyEvent.VK_LEFT) left = true;
try{
}catch (Exception ex){} } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if(key == KeyEvent.VK_UP) up = false; else if(key == KeyEvent.VK_DOWN) down = false; else if(key == KeyEvent.VK_RIGHT) right = false; else if(key == KeyEvent.VK_LEFT) left = false; } }); up = down = left = right = false; run_switch = false; logicalX = logicalY = 0;
...
thr = new Thread(this); thr.start(); validate(); requestFocus();
} |
At first I used just validate, then I added requestFocus along with it.
Neither one appears to work.
This looks like what I need (according to the API), but I think
my usage isn't right.
-Phoenix412