开发者

How to call self component in Java swing?

I have many buttons in a button group that need to search a database using their containing text as the query when toggled.

Instead of typing out specific event code for each button, how do I call a button's self?

Desired pseudocode: 开发者_JAVA百科 searchDB(genericSelf.getText())

Tried using the this keyword and fiddling with getComponent, but I'm sure there exists a more efficient way.


How about:

public void actionPerformed(ActionEvent evt) {
    JButton source = (JButton) evt.getSource();
    // source is your "this"
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜