2012-04-11 5 views
0

私は、マウスがアプリケーションに入る時をチェックするマウスモーションリスナーがあることを知っています。ユーザーがアプリケーションに入ったときにマウスを画面の中央に移動させる方法はありますか?これの例は、ゲームMinecraftからのものです。ユーザーがアプリケーション内でマウスポインターをマウスポインターよりも移動させると、マウスポインターが画面の中央に表示され、マウスの動きによって表示されている内容が変化します。私はこれを達成しようとしていますが、マウスポインターを物理的な人間の操作から画面に移動させることなく、マウスの座標を画面の原点に変更する方法を知りたいだけです。マウスが画面に入ったときにマウス座標を画面中央に変更できるJava関数はありますか?

public static void main(String[] args) { 
    Jogl3DApp display = new Jogl3DApp(); 
    // make display listen for mouse events 
    display.addMouseListener(display); 
    // make display listen for keyboard events 
    display.addKeyListener(display); 
    // Uncomment the following line to create a timer object and start it 
    // generating events, one every 30 milliseconds 
    new Timer(10, display).start(); 
    // make display listen for the OpenGL graphics events 
    display.addGLEventListener(display); 

    // create a GUI window 
    JFrame window = new JFrame("Jogl Application"); 
    // make window contain the display object 
    window.setContentPane(display); 

    window.setLocation(100, 100); 
    window.setVisible(true); 
    // A JFrame object's size includes the window decorations, like 
    // the title bar and borders. So if you want a 500x500 drawing space, 
    // you must set the window size a little bit bigger than that. Insets 
    // gives 
    // you the size of the decorations, so you make the window of size 
    // 500x500 
    // plus the size of the decorations. 
    Insets insets = window.getInsets(); 
    window.setSize(500 + insets.right + insets.left, 500 + insets.top 
      + insets.bottom); 

    // kills thread (in particular the timer event thread) when window is 
    // closed 
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

} 
    public void display(GLAutoDrawable drawable) { 

    // get the OpenGL context object 
    GL gl = drawable.getGL(); 
    GLU glu = new GLU(); 
    GLUT glut = new GLUT(); 
    // clear the window 
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); 

    // replace what follows with your own drawing code 
    gl.glMatrixMode(GL.GL_MODELVIEW); 
    gl.glLoadIdentity(); 
} 

答えて

2

java.awt.Robotクラスを使用できます。ユーザーが画面とやりとりしている間にマウスを動かすことは確かではありませんが、UXは良い選択ですが、そのクラスでは必要なものを使い始めることができます。

final Robot robot = new Robot(); 
robot.mouseMove(100, 100); 

Robot - Javadoc

+0

一人称シューティングゲーム – tdelaney18

+0

に使用し、そのあなたは、マウスを移動したり、ゲーマーの視点を変更しようとしていますか? – Perception

+0

さて、この質問は、マウスポインタの移動方法を尋ねています。スクリーンの原点でマウスを特定の位置に動かすと、ゲーマーの視点を変えることについて後で質問を投稿することがあります。とにかくこのコードにはエラー処理があります。ロボットでエラーを処理する方法 – tdelaney18

関連する問題