罐子不工作?

时间:2013-08-22 06:35:10

标签: java eclipse error-handling error-detection

我已经创建了一个应用程序(在Java中)并使其受密码保护:当我在Eclipse中运行/编译我的代码时,它工作正常,但是当我创建一个jar文件并运行该jar时它无法正常工作:它显示了我最初的框架,但之后没有任何作用:

最初,当我创建第一个jar时,一个工作正常,但当我只是添加密码重置功能时,它就停止工作:

在回答之前请记住,代码在编译器(即Eclipse)中运行良好,但在转换为jar时无效。

转换程序:File>Export>Runnable Jar(选择的选项 - package required libraries into jar

在Eclipse中有效的输出 - 屏幕截图图像here http://i.stack.imgur.com/eVigb.jpg

一个不起作用的(从jar执行) 屏幕截图here http://i.stack.imgur.com/9oDOA.jpg

相关的一段代码(考虑声明和初始化的每一件事)

public JFrame psFrame=new JFrame("Password Check");
    private JPasswordField psField;
        private static int  tries=5;
    static boolean condition=false;
    private String Check,password;


        //////////// CONSTRUCTOR  ///////////
public  MenusAndButtons(){
    super("Explorer");
    extraString=null;
    try {passwordSetter();}catch (FileNotFoundException e){e.printStackTrace();}
    paswardCheck();

}


public synchronized  void  paswardCheck(){


Check=null;
psFrame.setSize(400, 120);
psFrame.setLocation(480, 300);

psField=new JPasswordField("",30); 
psField.addActionListener(new ActionListener(){

    @Override
    public void actionPerformed(ActionEvent e) {

        if(e.getSource()==psField){ 
            Check=e.getActionCommand();

    if(tries!=1){


                if(Check!=null){


                             if(password.equals(Check)){
                             JOptionPane.showMessageDialog(null, "Welcome to Explorer ", "Welcome", JOptionPane.INFORMATION_MESSAGE);
                             condition=true;
                             psFrame.dispose();
                             Mnb();}
                             else{tries--;
                             JOptionPane.showMessageDialog(null,"You Entered a Wrong Password.\nYou are Left With " +tries+ " more Tries.\nPlease complete The Password Check with Correct Password\n", "Warrnning ",JOptionPane.WARNING_MESSAGE);  
                             psField.setText(null); }


                }else{JOptionPane.showMessageDialog(null,"You Entered Nothing in Password Field.\nPlease Enter a Password.","Null value Password Check",JOptionPane.ERROR_MESSAGE); 
                psField.setText(null);}


    }else{JOptionPane.showMessageDialog(null,"You Entered a Wrong Password 5 Times.\nExplorer is Quiting Now.","Password Check Failed ",JOptionPane.ERROR_MESSAGE); 
    psFrame.dispose();
    System.exit(0);}


    }  

    }});
psFrame.setLayout(new FlowLayout());
psFrame.add(new JLabel("Enter Password"));
psFrame.add(psField);
psFrame.setResizable(false);
psFrame.setVisible(true);


}




public void passwordSetter() throws FileNotFoundException{

    Scanner sc=new Scanner(new File("PasswordContainer.txt"));
    while(sc.hasNext())
        password=sc.nextLine();
    sc.close();

}

public void passwordresetter() throws Exception{


    String old=JOptionPane.showInputDialog(null,"Please Enter current Password","Current Password Check",JOptionPane.CANCEL_OPTION);
    if(old.equals(password)){
    String usererntry=JOptionPane.showInputDialog(null, "Please Enter new Password","Reset Password",JOptionPane.CANCEL_OPTION);

    if(usererntry.length()>=6){
    Formatter fp=new Formatter("PasswordContainer.txt");
    fp.format("%s",usererntry);
    fp.close();
    JOptionPane.showMessageDialog(null,"You've successfully Change Your Password","Password Change Conformation",JOptionPane.PLAIN_MESSAGE);
}else{  
    JOptionPane.showMessageDialog(null,"You Password Must Contain at least 6 Characters\nPlease Retype the New Password ");
    passwordresetter();}
        }


    else{JOptionPane.showMessageDialog(null,"You Entered Wrong Password\nPlease Retype the Current Password ");
    passwordresetter();
  }    
}

1 个答案:

答案 0 :(得分:0)

根据你的描述,听起来你的罐子没有像你想象的那样组装。

如果某个面板没有显示,那么您很可能错过了一个支持库。

我会打开jar文件并浏览内容。无论如何,当你学习Java时,这是一个有趣的练习(我注意到你是你的个人资料的学生)。浏览jar并确保它包含支持应用程序所需的一切。我的猜测是,你使用的任何框架都没有完全复制到你的罐子里。