0

I have a very strange problem, my application works perfect! Code looks ok, no visual error at all. Tested it a lot and no problems..... but when i exported it as a jar, it does not behave like in eclipse, the jpanel for logging in does not show, like it does in eclipse.

I just want to say this twice, the code is IDENTICAL! no changes at all! It works correctly when i run it in Eclipse IDE but when i export it as a Jar file and run it, it runs "incorrectly".

Here is a overview in code and pictures of the structure of my application and how it should behave and how it behaves when it is incorrect.

All relevant code in the GUI package is below.

Please if you comment, give me some concrete examples/advises/leads.

QUESTION : Why does the application "work" improperly and doesn't show the login panel that is created in the class: LoginPanelGui when i run it from jar.

Thanks in advance!! //Dino

enter image description here Here is some relevant code:

`public class StartApplication {
    public static void main(String[] args) throws Exception{
        MainFrameGui main = new MainFrameGui();
        main.openMainFrameWindow();
    }   
}`

`public class MainFrameGui {

    private JFrame mainFrame = null;
    private LoginPanelGui loginPanelClass = null;
    private CreateUserPanelGui createNewUserClass = null; 
    private MainPanelGui mainPanelClass =null;
    private DeleteUserPanelGui deleteUserClass =null;
    private DialogGui dialog=null;
    private JMenuBarGui menu_bar = null;

    public MainFrameGui(){
        createMainWindow();
        initlizeMenuBar();
    }

    public void openMainFrameWindow(){
        showLoginPanel();
        mainFrame.setVisible(true);
    }

    private void createMainWindow(){
        this.mainFrame= new JFrame();
        mainFrame.setIconImage(new ImageIcon("locked.png").getImage());
        mainFrame.setTitle("PasswordSafe 1.0");
        mainFrame.setVisible(false);
        mainFrame.setSize(new Dimension(505, 355));
        mainFrame.setLayout(null);
        mainFrame.setLocationRelativeTo(null);
        mainFrame.setResizable(false);
        mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        mainFrame.setLocation(200, 10);
        this.dialog = new DialogGui(this.mainFrame);
        addLoginPanelToMainFrame();
        addDeleteUSerToMainFrame();
        addCreateNewUserToMainFrame();
        addMainPanelToMainFrame();
    }

    private void initlizeMenuBar(){
        this.menu_bar = new JMenuBarGui(this, dialog, createNewUserClass, deleteUserClass, loginPanelClass);
        this.mainFrame.setJMenuBar(menu_bar.getJMenuBar());
    }


    private void addLoginPanelToMainFrame(){
        loginPanelClass = new LoginPanelGui(this, dialog);
        mainFrame.add(loginPanelClass.getJPanel()).setBounds(10, 10, 480, 305);
    }

    private void addCreateNewUserToMainFrame(){
        createNewUserClass = new CreateUserPanelGui(this,dialog);
        mainFrame.add(createNewUserClass.getJPanel()).setBounds(10, 10, 480, 365);
    }

    private void addMainPanelToMainFrame(){
        this.mainPanelClass = new MainPanelGui(dialog);
        mainFrame.add(mainPanelClass.getJPanel()).setBounds(10, 10, 1030, 620);
    }

    private void addDeleteUSerToMainFrame(){
        this.deleteUserClass = new DeleteUserPanelGui(dialog);
        mainFrame.add(deleteUserClass.getJPanel()).setBounds(10, 10, 480, 305);
    }

    public void showLoginPanel(){
        deleteUserClass.hideDeleteUserPanel();
        createNewUserClass.hideCreateNewUserPanel();
        mainPanelClass.hideMainPanel();
        loginPanelClass.showLoginPanel();
        mainFrame.setSize(new Dimension(505, 375));
    }

    public void showCreateNewUserPanel(){
        loginPanelClass.hideLoginPanel();
        deleteUserClass.hideDeleteUserPanel();
        mainPanelClass.hideMainPanel();
        createNewUserClass.showCreateNewUserPanel();
        mainFrame.setSize(new Dimension(505, 435));
    }

    public void showDeleteUserPanel(){
        loginPanelClass.hideLoginPanel();
        createNewUserClass.hideCreateNewUserPanel();
        mainPanelClass.hideMainPanel();
        deleteUserClass.showDeleteUserPanel();
        mainFrame.setSize(new Dimension(505, 375));
    }

    public void showMainPanel(LUANObject luan){
        loginPanelClass.hideLoginPanel();
        deleteUserClass.hideDeleteUserPanel();
        createNewUserClass.hideCreateNewUserPanel();
        mainPanelClass.showMainPanel(luan);
        mainFrame.setSize(new Dimension(1055, 690));
    }

    public String getLoginPanelSelectedAlgorithmMode(){
        return loginPanelClass.getSelectedAlgorithmMode();
    }

    public String getCreateNewUserSelectedAlgorithmMode(){
        return createNewUserClass.getSelectedAlgorithmMode();
    }

    public boolean isLoggedIn(){
        return mainPanelClass.isLoggedIn();
    }

    public void setLockedIcon(){
        mainFrame.setIconImage(new ImageIcon("locked.png").getImage());
    }

    public void setUnlockedIcon(){
        mainFrame.setIconImage(new ImageIcon("unlocked.png").getImage());
    }

    public void setUserLabel_menuBar(String userLabel){
        menu_bar.setUserLabel(userLabel);
    }

    public void removeUserLabel_menuBar(){
        menu_bar.removeUserLabel();
    }
}
`

`
import SecureFileManager.FileManager;

public class LoginPanelGui {
    private JPanel loginPanel = null;
    private FileManager fm = null;
    private DialogGui dialog = null;
    private MainFrameGui mainFrame=null;
    private JComboBox <String> comboBoxSelectAlgorithm = null;
    private JComboBox <String> comboBoxSelectuser = null;
    private JPasswordField passwordFieldEncryptionKey = null;
    private JPanel panelEncryptionKeyInfo=null;
    private JPasswordField passwordFieldIvKey=null;
    private JPanel panelFieldIvKeyInfo=null;
    private JPasswordField passwordField =null;
    private JPanel panelFieldPasswordInfo=null;
    private JLabel labelPassword =null;
    private JLabel labelEncryptionKey =null;
    private JLabel labelIvKey=null;
    private JButton buttonLogin=null;
    private boolean createNewUser=false;

    public LoginPanelGui(MainFrameGui mainFrame, DialogGui dialog){
        this.mainFrame = mainFrame;
        this.fm = new FileManager();
        this.dialog = dialog;
        createLoginJPanel();
    }

    private void createLoginJPanel(){
        initlilizeLoginPanel();
        addComboBoxAlghoritmToPanel();
        addLabelIvKeyToFrame();
        addLabelEncryptionKeyToFrame();
        addPanelEncryptionKeyInfoToFrame();
        addInitialVectorFieldToPanel();
        addLabelPasswordToFrame();
        addPasswordFiledAndPanelToFrame();
        addComboBoxSelectUserToPanel();
        addLoginButtonToFrame();
        isIvKeyCorrect();
        isKeyCorrect();
        isPasswordCorrect();
    }

    private void initlilizeLoginPanel(){
        loginPanel = new JPanel();
        loginPanel.setLayout(null);
        loginPanel.setBorder(BorderFactory.createEtchedBorder());
        loginPanel.setVisible(true);
    }

    private void addComboBoxAlghoritmToPanel(){
        String algorithms[]={"Select Algorithm","AES/CBC/PKCS5Padding","AES/CTR/PKCS5Padding","AES/ECB/PKCS5Padding","AES/GCM/PKCS5Padding","DES/CTR/PKCS5Padding"};
        comboBoxSelectAlgorithm = new JComboBox<String>(algorithms);
        Font font = new Font("Consolas", Font.BOLD, 20);
        comboBoxSelectAlgorithm.setFont(font);
        loginPanel.add(comboBoxSelectAlgorithm).setBounds(10, 10, 455, 40);
        comboBoxSelectAlgorithm.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                isIvKeyCorrect();
                isKeyCorrect();
                if(getSelectedAlgorithmMode().equals("Select Algorithm") || getSelectedUser().equals("Select User")){
                    buttonLogin.setEnabled(false);
                }
                if(!getSelectedAlgorithmMode().equals("Select Algorithm") && !getSelectedUser().equals("Select User")){
                    buttonLogin.setEnabled(true);
                }
                if(getSelectedAlgorithmMode().contains("DES")){
                    panelEncryptionKeyInfo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Enter Key (8 Characters)", 0, 0, new Font("Arial", Font.BOLD, 13)));
                    panelFieldIvKeyInfo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Enter Iv-Key (8 Characters)", 0, 0, new Font("Arial", Font.BOLD, 13)));

                }
                if(!getSelectedAlgorithmMode().contains("DES")){
                    panelEncryptionKeyInfo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Enter Key (16 Characters)", 0, 0, new Font("Arial", Font.BOLD, 13)));
                    panelFieldIvKeyInfo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Enter Iv-Key (16 Characters)", 0, 0, new Font("Arial", Font.BOLD, 13)));
                }
            }
        });
    }

    private void addLabelEncryptionKeyToFrame(){
        this.labelEncryptionKey = new JLabel();
        Font font = new Font("Ariel", Font.BOLD, 25);
        labelEncryptionKey.setFont(font);
        labelEncryptionKey.setHorizontalAlignment(JLabel.CENTER);
        labelEncryptionKey.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Key Status", 0, 0, new Font("Arial", Font.BOLD, 13)));
        loginPanel.add(labelEncryptionKey).setBounds(10, 55, 225, 50);
    }   

    private void addLabelIvKeyToFrame(){
        this.labelIvKey = new JLabel();
        Font font = new Font("Ariel", Font.BOLD, 21);
        labelIvKey.setFont(font);
        labelIvKey.setHorizontalAlignment(JLabel.CENTER);
        labelIvKey.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Iv-Key Status", 0, 0, new Font("Arial", Font.BOLD, 13)));
        loginPanel.add(labelIvKey).setBounds(245, 55, 225, 50);
    }   

    private void addPanelEncryptionKeyInfoToFrame(){
        this.passwordFieldEncryptionKey= new JPasswordField();
        this.panelEncryptionKeyInfo = new JPanel();
        panelEncryptionKeyInfo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Enter Key (16 Characters)", 0, 0, new Font("Arial", Font.BOLD, 13)));
        panelEncryptionKeyInfo.setVisible(true);
        panelEncryptionKeyInfo.setLayout(null);
        Font font = new Font("Arial", Font.BOLD, 35);
        passwordFieldEncryptionKey.setFont(font);
        passwordFieldEncryptionKey.setText("");
        panelEncryptionKeyInfo.add(passwordFieldEncryptionKey).setBounds(10, 20, 205, 30);
        loginPanel.add(panelEncryptionKeyInfo).setBounds(10, 105, 225, 60);
        passwordFieldEncryptionKey.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent arg0) {
                isKeyCorrect();
            }
            @Override
            public void keyReleased(KeyEvent arg0) {
                isKeyCorrect();
            }
            @Override
            public void keyPressed(KeyEvent arg0) {
                isKeyCorrect(); 
            }
        });
    }

    private void addInitialVectorFieldToPanel(){
        this.passwordFieldIvKey = new JPasswordField();
        this.panelFieldIvKeyInfo = new JPanel();
        panelFieldIvKeyInfo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Enter Iv-Key (16 Characters)", 0, 0, new Font("Arial", Font.BOLD, 13)));
        panelFieldIvKeyInfo.setVisible(true);
        panelFieldIvKeyInfo.setLayout(null);
        Font font = new Font("Arial", Font.BOLD, 35);
        passwordFieldIvKey.setFont(font);
        passwordFieldIvKey.setText("");
        panelFieldIvKeyInfo.add(passwordFieldIvKey).setBounds(10, 20, 205, 30);
        loginPanel.add(panelFieldIvKeyInfo).setBounds(245, 105, 225, 60);
        passwordFieldIvKey.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent arg0) {
                isIvKeyCorrect();
            }
            @Override
            public void keyReleased(KeyEvent arg0) {
                isIvKeyCorrect();
            }
            @Override
            public void keyPressed(KeyEvent arg0) {
                isIvKeyCorrect();   
            }
        });
    }

    private void addLabelPasswordToFrame(){
        this.labelPassword = new JLabel();
        Font font = new Font("Ariel", Font.BOLD, 17);
        labelPassword.setFont(font);
        labelPassword.setHorizontalAlignment(JLabel.CENTER);
        labelPassword.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Password Status", 0, 0, new Font("Arial", Font.BOLD, 13)));
        loginPanel.add(labelPassword).setBounds(10, 170, 225, 60);
    //  isIvKeyStatusInactivated();
    }   

    private void addPasswordFiledAndPanelToFrame(){
        this.passwordField= new JPasswordField();
        this.panelFieldPasswordInfo = new JPanel();
        panelFieldPasswordInfo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Enter Password (18-20 Characters)", 0, 0, new Font("Arial", Font.BOLD, 11)));
        panelFieldPasswordInfo.setVisible(true);
        panelFieldPasswordInfo.setLayout(null);
        Font font = new Font("Arial", Font.BOLD, 28);
        passwordField.setFont(font);
        passwordField.setText("");
        panelFieldPasswordInfo.add(passwordField).setBounds(10, 20, 205, 30);
        loginPanel.add(panelFieldPasswordInfo).setBounds(10, 235, 225, 60);
        passwordField.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent arg0) {
                isPasswordCorrect();
            }
            @Override
            public void keyReleased(KeyEvent arg0) {
                isPasswordCorrect();
            }
            @Override
            public void keyPressed(KeyEvent arg0) {
                isPasswordCorrect();    
            }
        });
    }

    private void addLoginButtonToFrame(){
        this.buttonLogin = new JButton();
        buttonLogin.setText("LOGIN");
        buttonLogin.setFont(new Font("Consolas", Font.BOLD, 35));
        buttonLogin.setEnabled(false);
        loginPanel.add(buttonLogin).setBounds(245, 242, 225, 50);
        buttonLogin.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                if(isIvKeyCorrect() && isKeyCorrect() && isPasswordCorrect() && fm.isfileExcisting(comboBoxSelectuser.getSelectedItem().toString())){
                    LUANObject luan = new LUANObject();
                    try{
                        luan.put("username", comboBoxSelectuser.getSelectedItem().toString());
                        luan.put("algorithm", comboBoxSelectAlgorithm.getSelectedItem().toString());
                        luan.put("password", new String(passwordField.getPassword()));
                        luan.put("ivKey", new String(passwordFieldIvKey.getPassword()));
                        luan.put("key", new String(passwordFieldEncryptionKey.getPassword()));
                        luan=fm.readEncryptedPassword(luan);
                        if(luan!= null && luan.containsString("password") && new String(passwordField.getPassword()).equals(luan.getString("password"))){   
                            if(luan.containsString("password")){
                                luan.removeString("password");
                            }
                            if(luan.containsString("ivKey")){
                                luan.removeString("ivKey");
                            }
                            if(luan.containsString("key")){
                                luan.removeString("key");
                            }
                            luan.put("key", luan.getString("passwordTable_Key"));
                            luan.put("ivKey", luan.getString("passwordTable_Iv-Key"));
                            if(luan.containsString("passwordTable_Key")){
                                luan.removeString("passwordTable_Key");
                            }
                            if(luan.containsString("passwordTable_Iv-Key")){
                                luan.removeString("passwordTable_Iv-Key");
                            }
                            luan=fm.readEncryptedPasswordTable(luan);
                            mainFrame.showMainPanel(luan);
                            mainFrame.setUserLabel_menuBar(luan.getString("username"));
                        }else{
                            dialog.dynamicErrorDialogWindow("Authentication Faild", "Wrong Iv-key and/or decryption-Key and/or password!");
                        }
                    }catch(Exception ex){
                        dialog.dynamicErrorDialogWindow("Authentication Faild", "Wrong Iv-key and/or decryption-Key and/or password!");
                    }   
                }
            }
        });

    }

    private void addComboBoxSelectUserToPanel(){
        String algorithms[]=fm.getUsers();
        comboBoxSelectuser = new JComboBox<String>(algorithms);
        Font font = new Font("Consolas", Font.BOLD, 20);
        comboBoxSelectuser.setFont(font);
        loginPanel.add(comboBoxSelectuser).setBounds(245, 178, 225, 50);
        comboBoxSelectuser.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(getSelectedAlgorithmMode().equals("Select Algorithm") || getSelectedUser().equals("Select User")){
                    buttonLogin.setEnabled(false);
                }
                else if(!getSelectedAlgorithmMode().equals("Select Algorithm") && !getSelectedUser().equals("Select User")){
                    buttonLogin.setEnabled(true);
                }
            }
        }); 
    }

    private boolean isIvKeyCorrect(){
        if(getSelectedAlgorithmMode().contains("AES/ECB")){
            labelIvKey.setForeground(new Color(0,150,0));
            labelIvKey.setText("NOT NEEDED");
            passwordFieldIvKey.setEnabled(false);
            passwordFieldIvKey.setBorder(BorderFactory.createLineBorder(new Color(0,150,0)));
            return true;
        }else if(!getSelectedAlgorithmMode().contains("DES") && passwordFieldIvKey.getPassword().length==16){
            labelIvKey.setForeground(new Color(0,150,0));
            labelIvKey.setText("IV-KEY CORRECT");
            passwordFieldIvKey.setBorder(BorderFactory.createLineBorder(new Color(0,150,0)));
            passwordFieldIvKey.setEnabled(true);
            return true;
        }else if(getSelectedAlgorithmMode().contains("DES") && passwordFieldIvKey.getPassword().length==8){
            labelIvKey.setForeground(new Color(0,150,0));
            labelIvKey.setText("IV-KEY CORRECT");
            passwordFieldIvKey.setEnabled(true);
            passwordFieldIvKey.setBorder(BorderFactory.createLineBorder(new Color(0,150,0)));//createEtchedBorder(new Color(0,150,0), new Color(0,150,0)));
            return true;
        }else{
            labelIvKey.setForeground(Color.RED);
            labelIvKey.setText("IV-KEY INCORRECT");
            passwordFieldIvKey.setEnabled(true);
            passwordFieldIvKey.setBorder(BorderFactory.createLineBorder(Color.RED));
            return false;
        }
    }

    private boolean isKeyCorrect(){
        if(getSelectedAlgorithmMode().contains("DES") && passwordFieldEncryptionKey.getPassword().length==8 ){
            labelEncryptionKey.setForeground(new Color(0,150,0));
            passwordFieldEncryptionKey.setBorder(BorderFactory.createLineBorder(new Color(0,150,0)));
            labelEncryptionKey.setText("KEY CORRECT");
            return true;
        }
        else if(!getSelectedAlgorithmMode().contains("DES") && passwordFieldEncryptionKey.getPassword().length==16){
            labelEncryptionKey.setForeground(new Color(0,150,0));
            labelEncryptionKey.setText("KEY CORRECT");
            passwordFieldEncryptionKey.setBorder(BorderFactory.createLineBorder(new Color(0,150,0)));
            return true;
        }else{
            labelEncryptionKey.setForeground(Color.RED);
            labelEncryptionKey.setText("KEY INCORRECT");
            passwordFieldEncryptionKey.setBorder(BorderFactory.createLineBorder(Color.RED));
            return false;
        }
    }

    private boolean isPasswordCorrect(){
        if(passwordField.getPassword().length>9 && passwordField.getPassword().length<21  ){
            labelPassword.setForeground(new Color(0,150,0));
            labelPassword.setText("PASSWORD CORRECT");
            passwordField.setBorder(BorderFactory.createLineBorder(new Color(0,150,0)));
            return true;
        }else{
            labelPassword.setForeground(Color.RED);
            labelPassword.setText("PASSWORD INCORRECT");
            passwordField.setBorder(BorderFactory.createLineBorder(Color.RED));
            return false;
        }
    }

    public String getSelectedAlgorithmMode(){
        return this.comboBoxSelectAlgorithm.getSelectedItem().toString();
    }

    public String getSelectedUser(){
        return this.comboBoxSelectuser.getSelectedItem().toString();
    }

    public boolean isCurrentModeLogin(){
        return createNewUser;
    }

    public void showLoginPanel(){
        updateComboboxUser();
        loginPanel.setVisible(true);
    }

    private void updateComboboxUser(){
        comboBoxSelectuser.removeAllItems();
        String algorithms[]=fm.getUsers();
        for(int i=0;i<algorithms.length;i++){
            comboBoxSelectuser.addItem(algorithms[i]);
        }
    }

    public void hideLoginPanel(){
        loginPanel.setVisible(false);
        mainFrame.removeUserLabel_menuBar();
        passwordField.setText("");
        passwordFieldEncryptionKey.setText("");
        passwordFieldIvKey.setText("");
        comboBoxSelectuser.setSelectedIndex(0);
        comboBoxSelectAlgorithm.setSelectedIndex(0);
        isIvKeyCorrect();
        isIvKeyCorrect();
        isPasswordCorrect();

    }

    public JPanel getJPanel(){
        return this.loginPanel;
    }
}
`

`
public class JMenuBarGui {


    private DialogGui dialog=null;
        private MainFrameGui mainFrameGui = null;
        private JMenuBar menu_bar = null;
        private JMenu accountManager_menu=null;;
        private JMenuItem login_menuItem=null;
        private JMenuItem logout_menuItem=null;
        private JMenuItem createUser_menuItem=null;
        private JMenuItem deleteUser_menuItem=null;
        private CreateUserPanelGui createPanel=null;
        private DeleteUserPanelGui deletePanel=null;
        private LoginPanelGui loginPanel=null;
        private JMenu help_menu;
        private JMenuItem instructions_menuItem;
        private JMenuItem about_menuItem;

    private JLabel userLabel= null;

    public JMenuBarGui(MainFrameGui mainFrameGui,DialogGui dialog, CreateUserPanelGui cp, DeleteUserPanelGui dp, LoginPanelGui lp){
        this.loginPanel=lp;
        this.createPanel=cp;
        this.deletePanel=dp;
        this.mainFrameGui = mainFrameGui;
        this.dialog=dialog;
        initilizeAccoutmanager_menu();
        initilizeHelp_menu();
        initilizeUserLabelToMenuBar();
        initilizeMenuBar();
        startLogin_menuItemEventListener();
        startCreateUser_menuItemEventListener();
        startDeleteUser_menuItemEventListener();
        startLogout_menuItemEventListener();
        startInstructions_menuItemEventListener();
        startAbout_menuItemEventListener();
        isLoggedInChangeListener();
    }

    private void initilizeMenuBar(){
        this.menu_bar = new JMenuBar();
        this.menu_bar.add(accountManager_menu);
        this.menu_bar.add(help_menu);
        this.menu_bar.add(Box.createGlue());
        this.menu_bar.add(userLabel);
    }

    private void initilizeAccoutmanager_menu(){
        this.accountManager_menu = new JMenu("Account Manager");
        this.accountManager_menu.setVisible(true);
        this.accountManager_menu.setLayout(new FlowLayout());
        this.login_menuItem = new JMenuItem("Login");
        this.createUser_menuItem = new JMenuItem("Create New User");
        this.deleteUser_menuItem = new JMenuItem("Delete An User");
        this.logout_menuItem = new JMenuItem("Logout");
        this.accountManager_menu.add(login_menuItem);
        this.accountManager_menu.add(createUser_menuItem);
        this.accountManager_menu.add(deleteUser_menuItem);
        this.accountManager_menu.add(logout_menuItem);
    }

    private void initilizeHelp_menu(){
        this.help_menu = new JMenu("Help");
        this.help_menu.setVisible(true);
        this.help_menu.setLayout(new FlowLayout());
        this.instructions_menuItem = new JMenuItem("Instructions");
        this.about_menuItem = new JMenuItem("About PasswordSafe");
        this.help_menu.add(instructions_menuItem);
        this.help_menu.add(about_menuItem);
    }

    private void initilizeUserLabelToMenuBar(){
        this.userLabel = new JLabel();
        this.userLabel.setVisible(false);
    }

    public JMenuBar getJMenuBar(){
        return this.menu_bar;
    }

    private void startLogin_menuItemEventListener(){
        class login_menuItem implements ActionListener{
            public void actionPerformed(ActionEvent e){
                mainFrameGui.showLoginPanel();
            }
        }
        login_menuItem.addActionListener(new login_menuItem());
    }

    private void startCreateUser_menuItemEventListener(){
        class createUser_menuItem implements ActionListener{
            public void actionPerformed(ActionEvent e){
                mainFrameGui.showCreateNewUserPanel();
            }
        }
        createUser_menuItem.addActionListener(new createUser_menuItem());
    }

    private void startDeleteUser_menuItemEventListener(){
        class deleteUser_menuItem implements ActionListener{
            public void actionPerformed(ActionEvent e){
                mainFrameGui.showDeleteUserPanel();
            }
        }
        deleteUser_menuItem.addActionListener(new deleteUser_menuItem());
    }

    private void startLogout_menuItemEventListener(){
        class logout_menuItem implements ActionListener{
            public void actionPerformed(ActionEvent e){
                boolean logout=dialog.dynamicConfirmationDialog("Log out", "Are you sure that you want to logout?");
                if(logout==true){
                    mainFrameGui.showLoginPanel();
                }
            }
        }
        logout_menuItem.addActionListener(new logout_menuItem());
    }

    private void startInstructions_menuItemEventListener(){
        class instructions_menuItem implements ActionListener{
            public void actionPerformed(ActionEvent e){
                System.out.println("MISSION SUCCESS");
            }
        }
        instructions_menuItem.addActionListener(new instructions_menuItem());
    }

    private void startAbout_menuItemEventListener(){
        class about_menuItem implements ActionListener{
            public void actionPerformed(ActionEvent e){
                System.out.println("MISSION SUCCESS");
            }
        }
        about_menuItem.addActionListener(new about_menuItem());
    }

    private void isLoggedInChangeListener(){
        //could not fit(can maximum enter 30000 characters )
    }

    public void setUserLabel(String userLabel){
        this.userLabel.setText("Logged in as: "+userLabel+"  ");
        this.userLabel.setVisible(true);    
    }

    public void removeUserLabel(){
        this.userLabel.setText("");
        this.userLabel.setBorder(BorderFactory.createEtchedBorder());
        this.userLabel.setVisible(false);
    }


}
`


`
public class MainPanelGui {
    private FileManager fm=null;
    private JPanel mainPanel=null; 
    private DialogGui dialog = null;
    private boolean loggedIn=false;
    private JTableStructure ts=null;

    public MainPanelGui(DialogGui dialog){
        this.fm = new FileManager();
        this.dialog = dialog;
        initilizeMainPanel();
        initilizePasswordTable();
    }

    private void initilizeMainPanel(){
        mainPanel = new JPanel();
        mainPanel.setLayout(null);
        mainPanel.setBorder(BorderFactory.createEtchedBorder());
        mainPanel.setVisible(false);
    }

    private void initilizePasswordTable(){
        this.ts = new JTableStructure(dialog, fm);
        this.mainPanel.add(ts.getPasswordTableScroll()).setBounds(10, 10, 1010, 600);
    }

    public JPanel getJPanel(){
        return this.mainPanel;
    }

    public void showMainPanel(LUANObject luan){
        ts.updateEntireTableFromFile(luan);
        mainPanel.setVisible(true);
        loggedIn=true;
    }

    public void hideMainPanel(){
        mainPanel.setVisible(false);
        ts.setLuanObectToNull();
        this.loggedIn=false;
    }

    public boolean isLoggedIn(){
        return this.loggedIn;
    }

}`
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 1
    I'd have a close look at your use of `null` layouts; I'd make sure you images are loading and generating `NullPointerException`s – MadProgrammer Feb 09 '16 at 13:25
  • 1) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). .. – Andrew Thompson Feb 09 '16 at 13:32
  • .. 2) Application resources will become embedded resources by the time of deployment, so it is wise to start accessing them as if they were, right now. An [tag:embedded-resource] must be accessed by URL rather than file. See the [info. page for embedded resource](http://stackoverflow.com/tags/embedded-resource/info) for how to form the URL. 3) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 4) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). – Andrew Thompson Feb 09 '16 at 13:32
  • BTW - run the Jar from the command line and report any errors (copy/paste them from the command line output). – Andrew Thompson Feb 09 '16 at 13:34
  • Guys, thanks so much, it's almost solved, there where a nullpointer exception because im trayng to open(decrypt) a file where i have passwords and in eclipse the folder is there, thats why it woks in eclipse but in the jar file the folder is either missing or hiding som where, it should be there because the picture/icon of the application is a orange lock, and it is visible on the application, which should prove that the folder should be somewhere in he jar file You can see on the overview picture of the classes, the folder Users, when i open the jar with winrar, the users folder is misssing – user3560377 Feb 09 '16 at 23:09
  • Guys, do you know how to convert this solution with this.class insted of using javas File class. public LUANObject readEncryptedPassword(LUANObject luan) throws Exception{ File file = new File("Users/"+luan.getString("username")+"/password.txt"); luan.put("bfile", convertFileToByteArray_IO(file)); byte[] decryptedByteArrFile= sec.decrypt(luan); String content=new String(decryptedByteArrFile, "ISO-8859-1"); return new LUANObject(content); } – user3560377 Feb 09 '16 at 23:23

0 Answers0