How to communicate between classes?

Whats the best way to communicate between two classes?

I have a main class that creates an object that displays images, and another object that user selects files on. I want some way for one object to tell the other one that a new file was chosen, and to display it.

How can I do this?

[311 byte] By [Terenius] at [2007-9-26 3:11:22]
# 1

1) You could put the two classes in the same source file, though only one can be made public (the one with same name as the file).

2) You could put both classes in the same package. Classes generally can call methods of other classes in the same package (unless the method is declared private).

It seems like all you have to do is select the file, then call the method in display class.

thomasfly at 2007-6-29 11:18:45 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2

Hello, thanks for replying. Actually I did have the program running before as you described, but I wanted to create independant objects existing in seperate .class files. This way feels more like proper object-oriented programming...

Anyways, just to clarify:

- Main creates ImageDisplayer.

- Main creates FileSelector.

- User selects a file with FileSelector

- How can I let ImageDisplayer know to display the new file?

Is it possible for me to create my own event, and have ImageDisplayer listening?

Terenius at 2007-6-29 11:18:45 > top of Java-index,Archived Forums,New To Java Technology Archive...