Results 1 to 2 of 2
  1. #1
    jjonesmu is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default How To Use Key Binding or Key Listener to move object

    I'm creating a pong game and I need help moving the boards.

    I have posted the codes for one of the boards.

    Java Code:
    private class PlayerOne extends Thread implements KeyListener {
    
            int width = gameBoard.getWidth();
    
    
            public void run() {
                while (true) {
                    paintPaddle();
                    doNothing(PAUSE);
                    setFocusable(true);
                    addKeyListener(this);
                }
            }
    
            public void paintPaddle() {
                Graphics g = firstPlayerSpace.getGraphics();
    
    
                g.setColor(Color.RED);
                g.fillRect(1, 180, 5, (width / 12));
            }
    
            public void keyTyped(KeyEvent e) {
            }
    
            public void keyPressed(KeyEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
    
            public void keyReleased(KeyEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
    
    
    
        }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Duplicate thread of this one: Help Using KeyListener to Move an Object

    Please let's avoid splitting the discussion of this problem in multiple threads.

    Locked.

Similar Threads

  1. Help Using KeyListener to Move an Object
    By jjonesmu in forum New To Java
    Replies: 3
    Last Post: 04-20-2010, 10:35 PM
  2. Mouse Listener for mouse floating over object?
    By Krooger in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 04:34 AM
  3. [SOLVED] Key binding Q
    By playwin2 in forum New To Java
    Replies: 3
    Last Post: 11-04-2008, 06:04 AM
  4. Spring binding in jsp
    By Pierre Javason in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-05-2008, 12:21 PM
  5. Adding listener to non-Java object?
    By cruxblack in forum Advanced Java
    Replies: 5
    Last Post: 07-30-2007, 02:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •