标签: swing
我有一个包含一系列按钮的程序,每个按钮都有一个mouselistener事件。
现在,我怎样才能找到通过鼠标监听器点击哪个按钮。
答案 0 :(得分:1)
响应按钮的常用方法是通过ActionListener,如How to Use Buttons中所述。这个example使用个人和公共听众来实现键盘。如果您实际使用MouseListener来查找组件,findComponentAt(int x, int y)可能会有用,如图here所示。
ActionListener
MouseListener
findComponentAt(int x, int y)