Re: [問題] 關於事件處理

看板java作者 (痞子軍團團長)時間17年前 (2008/02/27 21:55), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串3/11 (看更多)
※ 引述《akdsy (我喜歡小玉)》之銘言: : 我照著書上這樣寫, : 做按鈕的時候是利用 actionPerformed() : public void actionPerfromed(ActionEvent e) : { : Button btn = (Button) e.getSource(); : ................ : } : 這樣的確可以在按下按鈕之後做出反應, : 然後在做Menu的時候, : 他也是利用 actionPerfromed() : public void actionPerformed( ActionEvent e) : { : MenuItem mi = (MenuItem) e.getSource(); : ................... : } : 問題來了! : 可是要是同時做有 Botton 和 Menu 的時候, : 這樣要怎麼讓 Button 和 Menu 做區別呢! ㄜ... 你要區別什麼? 你可以讓 Button 跟 Menu 分別掛上(add)不同 ActionListener 這樣子就完全可以區別了阿... [茶] btw... 我實在很討厭很多書上範例用這種 也許你也是因為這種東西,才會有這種疑惑 XDXD public class XD extends JFrame implements ActionListener{} 另外... 建議你去看一下 ActionEvent.getCommand() 我比較喜歡用這個... 雖然不建議你利用這個去作你所謂的區別.... -- 侃侃長論鮮窒礙 首頁:http://www.psmonkey.idv.tw 眾目睽睽無心顫 Blog:http://ps-think.blogspot.com 煢居少聊常人事 殺頭容易告白難 歡迎參觀 Java 版(@ptt.cc)精華區 \囧/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.228.192.103

02/27 23:31, , 1F
getActionCommand()
02/27 23:31, 1F

02/27 23:53, , 2F
XD
02/27 23:53, 2F

03/01 00:48, , 3F
我也喜歡Get action command
03/01 00:48, 3F
文章代碼(AID): #17nMlEVo (java)
討論串 (同標題文章)
文章代碼(AID): #17nMlEVo (java)