关于弹出菜单监听事件的执行问题
代码如下!!package ethan;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JToggleButton;
import javax.swing.event.MouseInputListener;
public class FriendButton extends JToggleButton implements MouseListener {
private ContactMan friend;
TalkDialog dialog = new TalkDialog();
JPopupMenu righthelp = new JPopupMenu("righthelp");
JMenuItem m1;
{
m1 = new JMenu("更改好友资料");
righthelp.add(m1);
m1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("menuitem");
}
});
}
public FriendButton() {
// TODO Auto-generated constructor stub
super();
addMouseListener((MouseListener) this);
}
public FriendButton(ContactMan friend) {
super();
this.friend = friend;
}
public ContactMan getFriend() {
return friend;
}
public void setFriend(ContactMan friend) {
this.friend = friend;
}
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
checkPop(e);
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
checkPop(e);
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
checkPop(e);
}
private void checkPop(MouseEvent e) {
if (e.isPopupTrigger()) {
righthelp.show(this, e.getX(), e.getY());
}
else if (e.getClickCount() == 2) {
dialog.setTitle("你正和:"+ ((JToggleButton) e.getSource()).getText() + "聊天");
dialog.setVisible(true);
}
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
JFrame f=new JFrame();
f.getContentPane().add(new FriendButton());
f.pack();
f.setVisible(true);
}
}
想问下为什么点击弹出菜单("更改用户资料")没有反应?
请教各位兄台了!