0

当我第一次输入错误的密码时,showPopUpPassword 工作正常,但是当我第二次或更多次重复时。它仍然在 JOptionPane.showMessageDialog(null, "incorrect password"); 之后弹出。

    table.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON3) 
                {
                    popup.show(table, e.getX(), e.getY());
                    EditProfile.addActionListener(new ActionListener() {            
                        public void actionPerformed(ActionEvent e) {

                            int row = table.getSelectedRow();
                            String name = (String) table.getModel().getValueAt(row, 0);

                            if (!namelist.contains(name)) {

                                String pass =   ctr.getNamebyPassword(name, password);      // get password on database
                                password = showPopUpPassword();                             // get the user input password

                                if(!pass.equals(password)) {
                                    JOptionPane.showMessageDialog(null, "incorrect password");  

                                }else if (pass.equals(password)){
                                    edit =  new editProfileFrame(ctr.getData(name), ctr.getAccount(name));
                                    namelist.add(name);
                                }

                            }else {
                                JOptionPane.showConfirmDialog(null, "Cannot Duplicate Profile Window");
                                }



                        }
                    });
                }
        }
    });
4

2 回答 2

0

有人可能会读到这个问题。JoptionPane 重复的问题是因为 EditProfile 按钮位于 MousePressedEvent 内。

只需将按钮放在 MousePressedEvent 之外。

于 2015-03-24T08:43:59.043 回答
0

尝试这个,

while(true){
    password = showPopUpPassword();                         
    if(!pass.equals(password))
        JOptionPane.showMessageDialog(null, "incorrect password");  
    else
        break;
}

edit =  new editProfileFrame(ctr.getData(name), ctr.getAccount(name));
namelist.add(name);
于 2015-03-23T10:55:26.327 回答