• 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

Java2D and MVC

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this asignment to create a Java SWING application, which uses the Java2D functionality. The user should be able to draw points on the panel and by pushing the Create Polygon button to unite the points into a polygon. I'm not able to create the Points and I am also confused by the MVC Pattern, wich we are obliged to use! Can someone help me???








 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We usually discuss Swing on a different forum. Moving.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow! So much code! Let's narrow this down. What works? Then, where do things start to fall apart?

 
Nicole Gruber
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What works: the first time when the user clicks somewhere on the panel, that point is added in the Model-class, which notifices the Observer(View-class) [I omitted to write in the code
]
and finally the point is being drew through the paint() Method .
the Problem is that once you click twice on the Panel, the second point doesn't appear anymore...
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made changes to your code and it can now draw the points in your app.
I had to add the implementation for ChangeListener to get your code to compile.

One problem I encountered was with the Model entry method

Try this instead

In the MyDrawPanel class, pass in a reference to the Model at construction. No need to change the model each time there is a user change; the Controller class will make the change, update the Model and tell MydrawPanel to repaint itself. The MyDrawPanel class queries the Model for the current data.

About the Observer/Observable paradigm: the old/original way was to extend Observer and implement Observable. After the designers thought about it for a bit they came up with the idea of registering event listeners with components. So you can do your app with the antique Observer/Observable mechanism or use the current/newer event listener approach, which you already have in the Controller class.

You have your code encapsulated into classes according to the mvc design well enough as–is.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic