Communicating between components

Hey folks,

Is there a "best practices" pattern to communicating between GUI Components?

For example: Say I have the following GUI component hierarchy:

Main Application:

JFrame (Main Application Window)

JPanel (Contains a textfield for displaying user input)

JTextField

JButton (When clicked, opens up a wizard that prompts the user for a string)

Wizard:

JDialog (Prompts the user for his/her name), on submit sends it back to the TextField

I hate asking this question, because it seems pretty fundamental, but I have one fairly large book on Swing, and have Googled fairly extensively, but is there another method of passing information between components besides creating a long chain of mutators?

If you know of any good resources on the subject, they would be much appreciated.

Thanks!

Joe

[879 byte] By [Joe_ha] at [2007-11-27 7:37:53]
# 1

hi!

this can be achieved in many ways. depending upon the way you are now doing the job. so you need to create a

[url=http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example

Program[/url] (SSCCE) that demonstrates the incorrect behaviour.

Don't forget to use the [url=http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url]

so the posted code retains its original formatting.

regards

Aniruddha

Aniruddha-Herea at 2007-7-12 19:18:31 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks for the response,I'm sorry, but I'm not looking for a solution to a specific problem, but rather resources on the best ways of accomplishing interactions between components. Book recommendations/web tutorials would be fantastic!Thanks!Joe
Joe_ha at 2007-7-12 19:18:31 > top of Java-index,Desktop,Core GUI APIs...
# 3

don't know about 'best practice', but all you'd need in the button's actionPerformed() is

String textfieldText = new MyDialog().getData();

//check for null/empty/whatever

textField.setText(textfieldText);

where MyDialog is a class that extends JDialog, is modal, throw in a parent, and

the method getData() returns what is entered into the dialog field/s when the

dialog closes

Michael_Dunna at 2007-7-12 19:18:31 > top of Java-index,Desktop,Core GUI APIs...
# 4

... onButtonClicked()

{

MyDialog d = new MyDialog(this.textFieldValiable);

d.setVisible(true);

}

The idea is "only dialog knows when it submitted or canceled". So, it have to set fields text or not to set.

class MyDialog extends JDialog

{

private JTextField target;

public MyDialog(JTextField target)

{

this.target = target;

}

.... onSubmit()

{

target.setText("submitted");

}

}

Something like this....

Message was edited by:

FirstName2

FirstName2a at 2007-7-12 19:18:31 > top of Java-index,Desktop,Core GUI APIs...
# 5
I guess that answers my question. I was hoping that Swing would have some sort of Qt-style connection mode. Anyway, its ease of use makes up for a lot of that.Thanks!Joe
Joe_ha at 2007-7-12 19:18:31 > top of Java-index,Desktop,Core GUI APIs...