日期:2014-05-19  浏览次数:20741 次

JPopupMenu
我用JPopupMenu 定义了一个变量JPopupMenu2,

JPopupMenu2.add(new JMenuItem( "Delete"));
JPopupMenu2.add(new JMenuItem( "Add"));

JPopupMenu2出现后,我用鼠标点击,如何获取我点击的是那个Item?

------解决方案--------------------
帮顶~ 没用过@
------解决方案--------------------
Java code

JMenuItem menu1 = new JMenuItem( "Delete"));
JMenuItem menu2 = new JMenuItem( "Add"));

JPopupMenu2.add(menu1);
JPopupMenu2.add(menu2);

menu1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    //delete处理
    }
});
menu2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    //add处理
    }
});