首页 \ 问答 \ 使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)

使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)

我正试图在我的JavaFX应用程序中获得鼠标单击的位置。 我有一个EventHandler:

EventHandler<Event> mouseHandler = new EventHandler<Event>() {
    @Override
    public void handle(Event event) {
        String eType = event.getEventType().toString();
        if(eType.equals("MOUSE_PRESSED")){
            //mouse position
        }
    }
};

这是在鼠标按下,释放和拖动时调用的。 我无法从Event获取鼠标的位置,当我尝试将EventHandler<Event>更改为EventHandler<MouseEvent>我收到消息Type paremeter 'java.awt.event.MouseEvent' is not within it's bounds; should extend to 'javafx.event.Event' Type paremeter 'java.awt.event.MouseEvent' is not within it's bounds; should extend to 'javafx.event.Event'

如何将其移至MouseEvents?


I'm trying to get the position of a mouse click in my JavaFX application. I have an EventHandler as so:

EventHandler<Event> mouseHandler = new EventHandler<Event>() {
    @Override
    public void handle(Event event) {
        String eType = event.getEventType().toString();
        if(eType.equals("MOUSE_PRESSED")){
            //mouse position
        }
    }
};

which is called on mouse press, release and drag. I'm unable to get the position of the mouse from Event and when I try and change EventHandler<Event> to EventHandler<MouseEvent> I get the message Type paremeter 'java.awt.event.MouseEvent' is not within it's bounds; should extend to 'javafx.event.Event'.

How can I move this over to MouseEvents?


原文:https://stackoverflow.com/questions/30985634
更新时间:2024-05-03 14:05

最满意答案

如果您在google jpsgcs.alun.random.Sampling搜索,则会收到有关此Sampling类的一些损坏的链接。 此外,如果你在这里浏览你可以看到在罐子里,你可以下载,甚至没有像random这样的包。 所以,可能由于某些原因被删除了...也许这个Sampling类被删除了,因为不能正常工作? 我可以建议你与编写这个库的人取得联系。


If you search in google jpsgcs.alun.random.Sampling, you get some broken links about this Sampling class. Moreover, if you browse here you can see that in the jar, that you can download, there is no more even such a package like random. So, probably that was removed for some reasons ... Maybe this Sampling class was removed because not working properly? I can just suggest you to get in touch with somebody that wrote this library.

相关问答

更多
  • 问题似乎是iOS 9以后的特定问题。 我也可以在其他设备中复制它。 问题似乎与UIWindow手势识别器有关。 当我检查你的(@iphonic)示例代码时,我发现如果我在该特定位置点击并按住一秒钟,那么drawRect将被调用:)。 所以在我看来,那些地方的delay in touches有所delay in touches 。 所以我开始调试不同地方的触摸,发现_UISystemGestureGateGestureRecognizer这是一个私有类在这些区域有不同的属性,我做的是我只是通过附加到UIWin ...
  • 您可以看到的效果是视错觉。 您可以通过对颜色进行分级来使其可见。 请参阅stackoverflow问题的答案问题在glsl es 2.0,Gamemaker Studio 2.0中获取渐变方块 。 要获得更好的结果,您可以使用着色器平滑地更改渐变,从视图中间的圆形(或椭圆)渐变到视图边框处的方形渐变: void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Normalized pixel coordinates (from 0 to ...
  • 您将其作为纯单元测试运行,没有Spring上下文。 因此,存储库将不会自动装配。 您应该能够通过在测试类的顶部添加一些注释来解决这个问题。 如果使用Spring Boot,那么像下面这样的东西应该可以工作,让Spring Boot做所有艰苦的工作: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = MyApplication.class) 您也可以加载Spring @Configuration ...
  • 这不行 w=w.toUpperCase().replace(w.substring(1), w.substring(1).toLowerCase()) 因为w.substring(1)与w.toUpperCase 。 基本上你有...... w = "MY NAME IS ALEX".replace("y Name Is Alex", "y name is alex"); 正如您所看到的,没有什么可以匹配String 。 大写字符与提供的String值不匹配 你的双线方法更像是...... w=w.t ...
  • 如果您在google jpsgcs.alun.random.Sampling搜索,则会收到有关此Sampling类的一些损坏的链接。 此外,如果你在这里浏览,你可以看到在罐子里,你可以下载,甚至没有像random这样的包。 所以,可能由于某些原因被删除了...也许这个Sampling类被删除了,因为不能正常工作? 我可以建议你与编写这个库的人取得联系。 If you search in google jpsgcs.alun.random.Sampling, you get some broken links ...
  • 我明白,“表单”是指电子表格,即工作簿,文档和文件,因为在同一电子表格上的多个工作表上使用脚本不需要为每个脚本授权脚本,因为您看到“大量用于授予权限的条目“ 我也明白你的脚本是在一个脚本项目上绑定到一个电子表格。 当我们制作一个电子表格的副本时,它将包含一个到它所绑定的脚本项目的副本。 新的电子表格及其有限的项目,因为它们是不同的文件和Google的政策,运行脚本的授权是由脚本项目给出的。 避免拥有相同代码的许多副本并且必须授权他们每个人的方法是使用附加组件,这就是我投票选择在所有电子表格中重复使用脚本来关 ...
  • 看起来你走在正确的轨道上。 让我们假装我运行Do-PromptTask,选择任务1,然后单击运行... 来自Prompt-SelectionList的$ result变量将传递回Switch语句,此时超出范围 。 该开关正在完成其工作并匹配条件,然后打印$ task1_exec,但此时$ result无用。 如果要将$ task1_exec存储为变量,则需要设置与其相等的值。 但是,我会说你可以在switch语句中对它进行操作而不将其存储在变量中,如果这是有意义的话。 更少的代码方法...... f ...
  • 长时间你可以表示-9,223,372,036,854,775,808到+9,223,372,036,854,775,807 ( 来源 )之间,因此很快通过该范围的阶乘就会出现错误。 With long you can represent between -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 (source)so as soon the factorial pass that range you start to get errors ...
  • 您可以使用第一次滚动大于或等于250时设置的标志,并在滚动小于250时重置它(这样如果用户向下滚动,向上和向下滚动,它仍然会再次触发)。 $(document).ready(function(){ var flag = false; function someFunction() { $(".someContent .someYellowOverlay").toggleClass("someAnimation").delay(250).queue(function(next ) { $ ...
  • 尝试将代码更改为setTimeout,如下所示: //ensure interval variable are accessible var myInterval = null; var autoScroll = function() { jQuery.fn.fullpage.moveSectionDown() }; window.laytheme.on("newpageshown", function(layoutObj, type, obj){ if(obj.id === 11){ ...

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的