JDK-4091869 : rfe: mouse capture
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.4
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-11-11
  • Updated: 1999-12-21
  • Resolved: 1999-12-21
Related Reports
Duplicate :  

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
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)



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

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)

WORK AROUND Name: joT67522 Date: 11/11/97 ======================================================================

EVALUATION This cannot be added at the Swing level -- it requires native code changes. georges.saab@Eng 1999-06-25