访问对话框后形成冻结问题

时间:2013-12-30 16:07:24

标签: java swing

我正在为游戏创建登录机制。如果用户输入了无效的用户名 - 密码组合,则会出现一个对话框,告诉他们错误。但是,当我在对话框中单击“确定”时,上一个表单中的所有组件都将变为非活动状态。

以下是我的事件处理程序方法代码:

//Event Handler
public void actionPerformed(ActionEvent e){

    Scanner fileScan = null;
    Scanner passwordScan = null;


    String lineVar; 
    int lineCount=0;

    //Opens the "Create Account" form
    if (e.getSource()==CreateNew){      
        new CreateAccount();        
    }

    //user tries to login 
    else if(e.getSource()==submit){

        Inputuser = user.getText();
        InputPass = Pass.getText();

        try{
            fileScan = new Scanner(new File(Inputuser + ".txt"));
            filefound = true;
        }

        catch(FileNotFoundException ex){
            JFrame FailureFrame = new JFrame("Something went wrong...");
            JOptionPane.showMessageDialog(FailureFrame, "The username you have entered does not exist in our records. Please try again");
            filefound=false;
        }

        //If the file was found (username exists)
        if (filefound==true){

            //Loops while the username while has more lines of content          
            while(fileScan.hasNext()){
                lineVar = fileScan.next();

                //Each line is considered a token
                passwordScan = new Scanner(lineVar);
                passwordScan.useDelimiter("/n");

                while (passwordScan.hasNext()){
                    lineCount +=1;

                    if (lineCount == 2){

                        if (InputPass.equals( passwordScan.next() ) ){

                                JFrame successframe = new JFrame("Success!");
                                JOptionPane.showMessageDialog(successframe, "Login Successful!");

                                frame.dispose();
                                new MainProfile();

                        }

                        //If the password they entered is wrong     
                        else{
                            JFrame notLogin = new JFrame ("Something went wrong...");           
                            JOptionPane.showMessageDialog(notLogin, "You have entered invalid info. Please try again"); 

                            CompEnable();   

                        }

                    }


                }

            }


        }


    }

}

1 个答案:

答案 0 :(得分:3)

下面有一些提示可指导您解决问题:

<强>题外话: