java - Swing - how to handle multiple cross-dependent components? -


this more general question: have quite complicated files table in swing (the data model not trivial) , , when when user clicks on entry , 2 other view components need change - file statistics view , , file content view - both on same screen.

one options have these components class definitions in same file , , have reference each other - make messy code.

the other option think of pass statistics , content components table object , , have him use - render table not - reusable anywhere else.

i'm sure there's better way - recommend do?

option 1:

class mypanel extends jpanel{  private mytable table; private myfileviewer fv; private myfilestats stats;  class mytable {    addmouselistener({ ... fv.update(); stats.update(); }) } class myfileviewer{...} class myfilestats{...} } 

options 2:

class mytable {     mytable(myfileviewer fv, myfilestats stats) { ...         addmouselistener({fv.update, stats.update ... }     }     } 

option 3: model–view–controller pattern, discussed here , in this outline. mvc hinges on observer pattern. instead of having each view update others, arrange each view register listener data model. when model changes, each view updates accordingly.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -