[RSS]

Communication Between JFrame Panels

by Joseph B. Cotton

I have two JFrames in my NetBeans application. On Frame A is a text box, and in Frame B is a button. I wish to push the button on B and have a message placed in the text box in A, (and visa versa).

To do this, I set a couple of static variables in my Main class to hold pointers to the FrameA and FrameB class instances. I opened FrameA in Main, and Opened FrameB in A. I set the static pointer to B in its constructor. Once the static pointers were set, I was able to call class methods from one to the other. Alternatively, I could set the JFrameA global pointer in the Frame A constructor, also.

Main has the two global variables
jc1.png

Frame A creates Frame B and also can execute a method in frame B (sets text in a text box)
jc3.png

In its constructor, Frame B sends its own identity up to the global variable. This allows Frame A to execute Frame B methods. Also here in FrameB, execute method in FrameA.
jc4.png


Have a programming question or need help using Sun products or community technologies in your development projects? Get Sun Developer Expert Assistance! This online support service for developers provides technical assistance for code support, programming questions, and diagnostic advice to resolve problems. Buy Now

Attachments

jc1.png Info on jc1.png 33700 bytes
jc3.png Info on jc3.png 37399 bytes
jc4.png Info on jc4.png 36136 bytes