作者animp (阿宁)
看板java
标题[问题] 同时使用KeyListener和ActionListioner的问题
时间Mon Jun 26 20:05:49 2006
请问板上各位大大
我写了一个程式
大概长这样
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