Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4091869

rfe: mouse capture

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.4
    • client-libs
    • x86
    • windows_95



      Name: joT67522 Date: 11/11/97


      It would be nice to be able to capture the mouse
      in a JComponent. Relative mouse movement on top
      of that without tracking it myself would be nice
      tool. This is very useful for games and such.

       
      The ability to keep a mouse cursor locked within a window so it
      can not focus other windows. A ClipCursor win32 equivalent would
      work. The reason is this.. Say you have this nifty 3d world and
      you want to drive around it using the mouse. All you care about is
      relative mouse movement, not position. In fact, the cursor should
      be hidden. A work around is to at every frame note where the cursor
      is and move it back to the center of the screen. The only way to
      do it right now is via a native call which sucks for portability.

      If you want to really be nice to game developers, the best way would
      this. I will just explain it in some code. The idea is that all the
      stuff
      used below would be in the default classes.


      public class ExamplePanel extends JPanel implements MouseMotionListener
      , KeyListener
       {
       boolean exclusiveState=false;
       
       public void mouseDragged(MouseEvent e){}
       public void mouseMoved(MouseEvent e){}
       public void mouseMovedRelative(MouseEvent e)
        {
        int deltaX=e.getX();
        int deltaY=e.getY();

        // use deltaX and deltaY to do something useful like rotate a camera
      or something

        }

       public void keyTyped(KeyEvent e){}
       public void keyReleased(KeyEvent e){}
       public void keyPressed(KeyEvent e)
        {
        if(e.getKeyCode()==e.VK_ESCAPE)
         {
         if(!exclusiveState)
          {
          setExclusiveState(true);
          showCursor(false);
          exclusiveState=true;
          }
         else
          {
          setExclusiveState(false);
          showCursor(true);
          exclusiveState=false;
          }

         }

        }

      This adds a couple commands to the jcomponent

      public void setExclusiveState(boolean state);

      public void showCursor(boolean state);

      So what it does is it will take over the mouse every other time you hit
      escape.


      If you have any questions, feel free to ask.. This is a very important
      feature if
      java is going to have commercial games built specifically for it.

      (Review ID: 19233)
      ======================================================================

            rraysunw Richard Ray (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: