Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to return value from child gui to parent class  RSS feed

 
manab abu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,


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?


With regards
manab
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manab,
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)


 
manab abu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your immediate reply,

I have one more doubt.

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?

Thanks &
Regards
Manab
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
manab abu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi Maneesh thanks very much for your help.

i didn't find any link to mark it answered as in sun forum.

Manab
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
Here at the Ranch, you need not set it as answered. So there is no link.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!