Referencing

V

vik

Suppose I have defined separate classes by extending JFrame, JTable and and
JTree. I want to place the JTable and JTree in the JFrame. When someone
clicks on an item in the JTree I want the JTable to be updated with some
information based on the selection. What is the best way to do this?
Should a reference to the JFrame be passed to the constructors of JTable and
JTree when they are instantiated? Can a link be made between the JTree and
JTable without doing this?

Thanks.
 
J

Jon A. Cruz

vik said:
What is the best way to do this?
Should a reference to the JFrame be passed to the constructors of JTable and
JTree when they are instantiated?

Could, but probably not "should".

Can a link be made between the JTree and
JTable without doing this?

Yes.

Treat JFrame, JTable, etc as the "skin" of your application.

Define some Data models that represent the "muscle and bone"
functionality of your program.

Then just 'hang' the 'skin' on the 'muscle and bone'.

That is, have a set of classes modelling the concepts behind your
program. Then connect different UI widgets as the "skin" to the
appropriate model classes. Change propogate throught the model classes,
and then listeners in the 'skin' classes get called back to reflect changes.

So, each UI thing only knows about the core model classes, and not other
UI things (in general). When you instantiate the JFrame and JTable
subclasses, pass them one or more data models that would be needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top