private JPopupMenu popup = new JPopupMenu();
//创建菜单
public void createPopMenu() {
popup.add(new JMenuItem(new AbstractAction("设置为净房") {
public void actionPerformed(ActionEvent e) {
oneRoomBean.setRoomState(RoomState.净房);
refresh();
}
}));
popup.add(new JMenuItem(new AbstractAction("设置为脏房") {
public void actionPerformed(ActionEvent e) {
oneRoomBean.setRoomState(RoomState.脏房);
refresh();
}
}));
}
// 按钮事件
loginButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
int mods = e.getModifiers();
int iClickCount = e.getClickCount();
if ((mods & InputEvent.BUTTON3_MASK) != 0) {
// 判断是鼠标右键
// 弹出菜单
popup.show(e.getComponent(), e.getX(), e.getY());
}else if(iClickCount>=2) { //判断是否是双击
}
}
});