日期:2014-05-20  浏览次数:21467 次

JAVA如何判断按钮是否被单击
单击不同的按钮,显示不同的内容到字段域
3个按钮都绑定了时间监听器对象
在一个继承mouselistener借口的类的public   void   mouseClicked(MouseEvent   e)方法中如何实现,不懂的就是怎么判断按钮被单击

------解决方案--------------------
可以添加ActionListener监听就行了,一定要用鼠标监听么?
------解决方案--------------------
为什么要实现MouseListener接口,而不实现ActionListener这个接口呢
setActionCommand( " ");这个方法可以设置按钮的动作命令,在actionPerformed中判断究竟点了那个按钮
------解决方案--------------------
if(e.getClickCount()==e.BUTTON1)
{
System.out.println( "单击 ");
}
------解决方案--------------------
应该用mouseClicked就可以解决你的问题,其实用ActionListener最好了

void mouseClicked(MouseEvent e)
Invoked when the mouse button has been clicked (pressed and released) on a component.
void mouseEntered(MouseEvent e)
Invoked when the mouse enters a component.
void mouseExited(MouseEvent e)
Invoked when the mouse exits a component.
void mousePressed(MouseEvent e)
Invoked when a mouse button has been pressed on a component.
void mouseReleased(MouseEvent e)
Invoked when a mouse button has been released on a component.