English 中文(简体)
java的用途地点
原标题:Mouse location in java

我正在 Java培养第一手枪手,我希望实施控制,使汽车的移动能够轮到参与者。 然而,在 Java,我只能通过使用<代码>MouseListener的活动来获得模拟坐标,因此,一旦 mo曲者离开监测边缘,我就无法改变参与者的意见。

任何关于如何做到这一点的推论/建议? 感谢。

最佳回答
问题回答

I tried using a java.awt.Robot as AerandiR suggests, but there were a couple of problems I ran into, and it s possible other people will run into them as well, so I will elaborate.

如果您的目标是使 cur处于一种地位(最好是屏幕中心),那么你就希望打上像<代码>/robot.mouseMove(width/2,width/2);,在您的<代码>上。 在实施后,每当烟雾转移到中心时,Robot就会将其移回中心。

但是,当重新标注该 mo时,该 player子将回到原处。 实际上,参与者将在原职位和倒置立场之间 st。

为了确定这一点,而不是界定你的角色在多大程度上改变了现在和现在的距离,将其定义为与中心之间的距离。

类似:turnAmountX += e.getX() - width/2;

现在,如果<条码>Robot 重新定位,则总能产生零。

Recap:

    void mouseMoved(MouseEvent e) {
        turnAmountX += e.getX() - width/2;
        turnAmountY += e.getY() - height/2;
        robot.mouseMove(this.getLocationOnScreen().x + width/2, 
            this.getLocationOnScreen().y + height/2;
    }




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签