| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1368 人关注过本帖
标题:关于弹出菜单监听事件的执行问题
只看楼主 加入收藏
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
结帖率:100%
收藏
 问题点数:0 回复次数:0 
关于弹出菜单监听事件的执行问题
代码如下!!
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);
    }
}
想问下为什么点击弹出菜单("更改用户资料")没有反应?
请教各位兄台了!
搜索更多相关主题的帖子: import awt event java swing 
2008-01-15 11:21
快速回复:关于弹出菜单监听事件的执行问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017940 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved