让 JSlider 栏在鼠标单击事件上移动
我有一个 JSlider,它显示赌注大小(对于扑克游戏),我试图实现这样的效果:当鼠标单击发生时,滑块向前跳跃赌注金额(即大盲注金额),而不是仅增加一。如果鼠标单击发生在栏的左侧,我希望它减少固定量,否则增加。我考虑附加一个鼠标侦听器,但不知道如何使用该事件来找出鼠标单击了栏的哪一侧。
有什么想法吗?
I have a JSlider which shows bet sizes (for a poker game) I am trying to achieve the effect that when a mouse click occurs the slider jumps forward by a bet amount (i.e. a big blind amount) rather than just incrementing by one. If the mouse click happens to the left of the bar i want it to decrement by a fixed amount else increment. I looked into attaching a mouse listener, but do not know how I can use the event to find out on what side of the bar the mouse was clicked.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你只需要改变你对问题的看法。
不要将点击视为当前投注的“左侧”或“右侧”(下方或上方)。
相反,您只需存储旧的刻度,然后查看新的刻度是什么。该差异将告诉您用户是否尝试增加(正增量)或减少(负增量)。
然后您可以增加您想要的“固定投注”金额。
You just need to change your perspective on the problem.
Don't view the clicks as being to the 'left' or 'right' (below or above) the current bet.
Rather, you simply store the old tick, and look at what the new tick is. The difference will tell you if the user has tried to increase (positive delta) or decrease (negative delta).
Then you can increment by your desired 'fixed bet' amount.
我认为你需要为此编写一个自定义用户界面。这应该可以帮助您开始:
I think you need to write a custom UI for this. This should get you started:
这就是我完成 MouseClickEvent 的方式
This is how i accomplish the MouseClickEvent