[問題] 同時使用KeyListener和ActionListioner的問題

看板java作者 (阿寧)時間19年前 (2006/06/26 19:57), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
請問板上各位大大 我寫了一個程式 大概長這樣 public class testFrame extends JFrame { JButton good; handle han; //這是一個implements ActionListener的class public testFrame() { good=new JButton("test"); han=new handle(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); handle_key handle1=new handle_key(I2); addKeyListener(handle1); add(good,BorderLayout.SOUTH); good.addActionListener(han); } } class handle_key implements KeyListener { public void keyPressed(KeyEvent e) { String temp=""; temp=temp+e.getKeyCode(); JOptionPane.showMessageDialog(null,temp); } public void keyTyped(KeyEvent e) {} public void keyReleased(KeyEvent e) {} } 就是把testFrame這個JFrame說他是KeyListener的handler 然後把一個JButton貼到JFrame上面 然後那個Button是ActionListener的handler (這個class的程式碼我就不放了) 程式執行之後一開始我按鍵盤還有會作動作 可是當我按下那個Button之後,我再按鍵盤就不會有動作了 請問這到底該怎麼辦呢 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.140.219
文章代碼(AID): #14dykW_U (java)
文章代碼(AID): #14dykW_U (java)