• Post Reply Bookmark Topic Watch Topic
  • New Topic

communication between two JFrames  RSS feed

 
Manish Dhasmana
Greenhorn
Posts: 18
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a simple problem. I want to transfer some parameters from one JFrame to another JFrame,what is the right and best way to do this?? For example, Consider a situation where I input my name and address in a jframe, then these parameters should be displayed in second JFrame.
Thank you in advance and if possible please send me similar example's code.
 
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
Originally posted by Manish Dhasmana:
... For example, Consider a situation where I input my name and address in a jframe, then these parameters should be displayed in second JFrame.



I would say there are two parts you need to figure out in such a kind of scenario.
1) How is the communication going to happen. This would depend mostly on where are the two frames running. In the same JVM? Different JVMs? Is the communication direct or through some Observer class or some server side component? Based on the answers to these question you need to figure out a correct mode of communication.
2) How is the data going to be transferred? Mind you this is different from 1 above.

I would approach it this way.
Define my own interface which implements Serializable.
Define my own class say UserInfo which implements this interface.
Provide a proper constructor to UserInfo along with required getter/setter methods.
Populate the object from user input in frame1. Then based on the answer to 1 above, I would pass this UserInfo to frame2 and process it accordingly.

This might sound like an overkill, but the advantages are this approach would work irrespective of the communication approach.
Needless to say, the solution you want might be as simple as to maintain a reference to frame2 in frame1 and expose some method which will accept two strings, one for name and other for address. But this depends mostly on answers to question 1 above.


Thank you in advance and if possible please send me similar example's code.

Take a look at this link
 
Manish Dhasmana
Greenhorn
Posts: 18
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want direct communication between the two frames in the same JVM. Now please tell me how to do this with the help of example I have given in the earlier post. If possible, please send code for a small example.
 
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
Originally posted by Manish Dhasmana:
I want direct communication between the two frames in the same JVM. Now please tell me how to do this with the help of example I have given in the earlier post. If possible, please send code for a small example.


I already told you how to do it.
What code do you have so far? Have you tried out anything on your own?
Do you know how to invoke a method on an instance? Do you know how to pass parameters as arugments? What exactly is stopping you?
 
Manish Dhasmana
Greenhorn
Posts: 18
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can't we perform this task without serialization. I haven't used serialization ever before.
 
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
Originally posted by Manish Dhasmana:
can't we perform this task without serialization. I haven't used serialization ever before.


Of course you can. Evidently you havent read my first reply carefully.

Needless to say, the solution you want might be as simple as to maintain a reference to frame2 in frame1 and expose some method which will accept two strings, one for name and other for address


So all you need to do is invoke the appropriate method on frame2 and pass the arguments (name and address and what not)
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UseTheForumNotEmail.

It's quite easy though:

When a button in MyFrame2 is pressed or something, you just call frame1.doSomething().
 
Manish Dhasmana
Greenhorn
Posts: 18
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very Rob, That is what I was looking for. Thank you very much.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!