I am developing an application in swing. In this i have a main class from which i am creating a login view. Authentication is done by login view and if it is success it will rturn boolean true and then the main class will load another frame after closing login view. But i am confused how to return value from the login view.
Whether i have to send the reference of main class to login view?
Welcome to the Ranch, we are happy to have you here
By login "view" I presume you mean a JFrame instance which displays the required login input fields like user name and password.
One of the ways to do this is
1) Your main class displays to the user, the login frame.
2) On successful validation, you create and display the main frame by calling its constructor
3) You hide the login frame by calling setVisible(false)
From the main frame we could load different child frames .
For eg. I need to load and display a document in a main frame. When i click an icon or menu item corresponding child frame will be loaded. This child frame is for searching files from the server. Server will return file details which is displayed in the child frame. When the user selects a file and request to lode it by clicking a button for "load file", the selected file must be loaded in the main frame.
I understood with my little knowledge that i need to pass the reference of the main frame to the child frame. So that i could use this reference to call the load function of mainframe passing it file details. Whether it is the right way to do it?
In case of scenarios you have described, the usual way to do it is using modal dialogs.
I am sure you have seen such kind of dialogs. Typically, there is a main UI. Some even triggers off and displays a new UI. However, till the second UI is being displayed on the screen, the user cannot interact with the main UI.
Swing provides a very convenient class to achieve this functionality.
Check out the JOptionPane API. There are numerous JOptionPane.showXXXDialog methods you can use.
For you requirement, the JOptionPane#showInputDialog would be suitable where you can pass an array of selection values, which would be the file names retrieved from the server.
Check out the API for usage of these methods.