- 论坛徽章:
- 0
|
Hi, all
I've been looking if there is a standard/mostly-used way implementing GUI applications. e.g.,
under a JFrame, there are 2 MyPanel exntending JPanel, one placed on the leftside, the other on the rightside. they both have got a bunch of JButtons, JLabels, JList, etc. this is the view.
but for the control part, here comes the question: I'd would like PanelA to change background color if a Button on PanelB is pressed. where should I place this part of code that controls what happen. I've considered some possibilites, but not sure which one is the best.
1. implement it in main() like: if PanelA.Button.isPressed(), then PanelB.setBackground(Green)
pros: centrailized control
cons: could lead to long & messy code if there are many Panels needed to control
2. PanelA as Observer, PanelB Observable
pros: doable
cons: not very convenient
3. PanelA & PanelB both singleton, so they can reference to each other directly
pros: easy implementing
cons: less flexibility
if none of them is the way you do, how do you do it then?
any help will be appreciated.
thanks. |
|