Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in Observer pattern

 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I'm developing an applet for drawing rectangle with resize, color, borders etc

I have a ControlPanel for choosing tool ( Line, Oval, Rectangle ) and you can also choose color and bordercolor.

In the drawing area you can select multiple shapes resize them. When the shapes is selected I want to send updates to the controlpanel for updating the colors and I also want to send update message to some JSpinners that you also can use to resize the shapes with.

The problem is that the Update method of the Observer pattern needs to take several objects and the update in the JSpinner panel and the control panel need to take an array of active shapes. It seems rather tedious to passing objects and checking instance of in the update method

Isn't there a better approch for communication between GUI components. My old version put the JFrame, Panel in static variables so they could be accessed but I don't think this is a good approach. To have all Jframes, panels , dialogs in static variables.

Let me explain a problem

I have a color Picker for border colors and Background color for my shape classes. When a user clicks on the color in the controlpanel and chooses another color I want all my active shapes to update the colors. The same for the border. Problem is that the border color and the color is the exact same class. An TemplateColor class. When I pass the templatecolor class to the notifyObservers( myTemplateColor ) i can check instanceof in the update method but how will I know if it is regarding the border or the background? I could of subclass the TemplateColor but why? I must be missing something in this pattern. Can somebody please tell me on how to communicate properly between GUI classes. And don't want a reference to every class in every class that needs to be updated.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic