急!!鼠标右击事件
请问怎样或的鼠标右击事件?具体是这样的,我做了个QQ聊天的程序,在主窗口,好友列表那,我想右击好友头像后,让他出现JPopupMenu。哪位大狭告诉小弟,在线等了
------解决方案--------------------public void mouseReleased(MouseEvent e){
if(e.isPopupTrigger()){
popupMenu.show(e.getComponent(),e.getX,e.getY());
}
}
------解决方案-------------------- public void this_mousePressed(MouseEvent e) {
//判断是否是右击
if(e.getButton()==3){
//设置右键菜单出现的位置
this.jPopupMenu1.show(this,e.getX(),e.getY());
}
}
------解决方案--------------------this.addMouseListener(new MouseAdapter() {
public void mousePressed(final MouseEvent e) {
//MouseEvent.BUTTON1是左键 MouseEvent.BUTTON2是中键MouseEvent.BUTTON3右键
int button=e.getButton();
if (button == MouseEvent.BUTTON1)
{
........
} else if (button == MouseEvent.BUTTON2)
{
........
} else if (button == MouseEvent.BUTTON3)
{
..................
}
else
{
myJxta.setTextContent("发送鼠标点击事件的用户不存在");
}
}
});