| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 406 人关注过本帖
标题:关于弹出菜单监听事件的执行问题
收藏  订阅  推荐  打印 
george_vcool
Rank: 3Rank: 3
等级:中级会员
威望:3
帖子:447
积分:4618
注册:2007-7-23
关于弹出菜单监听事件的执行问题

代码如下!!
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-1-15 11:21
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.046106 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved