0

the showPopUpPassword work fine when I input incorrect password for the first time, but when i repeat it for the 2nd time or more. it still popUp after the 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");
                                }



                        }
                    });
                }
        }
    });
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Orville
  • 518
  • 7
  • 17
  • 1
    for better help sooner post an SSCCE/MCVE, short, runnable, compilable, with hardcoded value fro JTable/XxxTableModel in local variable – mKorbel Mar 23 '15 at 10:56
  • Don't use `if (e.getButton() == MouseEvent.BUTTON3)`. People may not know what button3 is. Instead you can use: `if (SwingUtilities.isRightMouseButton(e)`. – camickr Mar 23 '15 at 14:53

2 Answers2

0

Try this,

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);
Sanira
  • 334
  • 3
  • 7
  • endles loop isn't good suggestion in any of programming languages, read Oracle tutorial how to use JDialog, the part about JOptionPane – mKorbel Mar 23 '15 at 10:58
0

for someone may read this Problem.. The problem why the JoptionPane is repeating because the EditProfile Button is inside the MousePressedEvent.

Just Simply take the Button outside the MousePressedEvent.

Orville
  • 518
  • 7
  • 17