java鼠标问题ACM封装程序和图形
我有 2 个类,A 和 B。A 是 Program 的子类(即 acm.program.*),B 是 GCanvas
(即 acm.graphics.*
)。
在 AI 类中,有一个 init 方法,用于启动和添加 B 类。
在 BI 类中,我想实现两件事:我想响应窗口大小和鼠标单击的变化。我可以通过添加组件侦听器来实现窗口大小的更改。我无法实现鼠标点击事件。
现在,我知道在我不关心响应窗口大小调整的情况下该怎么做。我会有 1 个类,扩展 GraphicsProgram,并添加鼠标监听器,不会有任何问题。
你的建议是什么?如何让这两个事件处理程序同时存在于单个 GCanvas 中?谢谢。
I have 2 classes, A and B. A is a subclass of Program (i.e. acm.program.*) and B is a subclass of GCanvas
(i.e. acm.graphics.*
).
In Class A I have an init method which initiates and adds class B.
In Class B I have 2 things I want to achieve: I want to respond to changes in the window size and mouse clicks. I can achieve the window size changes by adding component listeners. I cannot achieve the mouse clicking events.
Now, I know how I would do it in a situation where I didn't care about responding to window re-sizing. I would have 1 class, extend GraphicsProgram, and add mouselisteners and not have any problem.
What is your recommendation? How do I have these two events handlers exist concurrently within a single GCanvas? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据文档,GCanvas 是一个 awt 组件,因此您始终可以调用此类
addMouseListener()
或addMouseMotionListener()
方法并用鼠标事件做你想做的事。As a GCanvas is, from the documentation, an awt Component, you can always call this class
addMouseListener()
oraddMouseMotionListener()
method and do what you want with mouse events.