Hey all,
I was just wondering if my calling the ship.keyPressed() method from the Main.class is the proper way to implement keyboard controls for the ship object (assuming I wish to use key presses for other than just the ship). This approach works fine though I can't help but feel it's somehow redundant.
Any feedback would be appreciated.
// Main.java public class Main extends JFrame { public class KeyHandler extends KeyAdapter { public void keyPressed(KeyEvent e_) { ship.keyPressed(e_); } } } //----------------------------------- // Ship.java public class Ship { int x, y; public Ship(int x_, int y_) { x = x_; y = y_; speed = 1; } public void keyPressed(KeyEvent e_) { if (e_.getKeyCode() == e_.VK_W) { y -= speed; } if (e_.getKeyCode() == e_.VK_S) { y += speed; } } }