爪哇 - 处理多个事件用一个函数? [英] Java - Handle multiple events with one function?
问题描述
首先,我是一个完整的Java NOOB。
First of all, I am a complete Java NOOB.
我要处理多个按钮presses一个功能,做这取决于被点击按钮某些事情。我使用NetBeans和我加入一个绑定功能的事件。这一功能默认是发送一个ActionEvent。
I want to handle multiple button presses with one function, and do certain things depending on which button was clicked. I am using Netbeans, and I added an event with a binding function. That function is sent an ActionEvent by default.
我如何被点击,以从该函数中触发绑定功能,对象,所以我知道去追求哪些功能?
How do I get the object that was clicked in order to trigger the binding function from within that function so I know which functionality to pursue?
推荐答案
发送该事件的对象是事件源,以便evt.getSource()会得到你。然而,这将是好得多有单独的事件不同的处理器。
The object that sent the event is the event source so evt.getSource() will get you that. However, it would be far better to have separate handlers for separate events.
这篇关于爪哇 - 处理多个事件用一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!