![](/img/trans.png)
[英]How to create swing Tabbed Pane application using the Netbeans GUI editor
[英]How to check which button was clicked using Netbeans GUI editor
然后讓我們說從按鈕在控制台文本中打印?
您編寫了一個通用偵聽器。 ActionEvent
包含被單擊的按鈕。
基本邏輯是:
ActionListener al = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();
System.out.println( button.getText() );
}
}
...
button1.addActionListener( al );
button2.addActionListener( al );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.