simple mvc starter

I’ve spent the evening creating a small boardgame for my little kid to play around with.
(used to do that using pygame back in the days when there was something called sparetime)

Anyway, I got stuck totally when it came to moving around the litlle pieces on the board. I couldn’t figure out how to design it correctly. Sure my mouseclicks fetched the little piece i was clicking at, but that piece could not report to its parent JPanels parent JFrame who had a textfield for in game messages. (for example)

So - the design was of course terrible. Are there any nice small, functional starters to dive into and get it right from the beginning?

Regards

It would be easier to help if you would show your code or at least explain in more detail how your program architecture is now.

I realize that, sorry. My code is a mess right now so the plan is to start over and try to get it right.

First I must look around the web and try to get a very basic example so I can get it right though. I’m confused how to handle the events in a nice way,I always want a textfield to catch the events when developing so I can see that it will work the way I wont it to.

In my terrible design, there were no way to accomplish that, I guess I better learn more about catching the events :wink:

There are lots, here is one: http://www.csis.pace.edu/~bergin/mvc/mvcgui.html

Basically, divide your code into model + view classes. The model classes hold your actual data. The view classes reference the models and manipulate them control functionality. For simplicity sake, just place your controller (e.g. action listeners) into your view classes…

Thank you, but having the view as the controller was exactly what i did. It didn’t work to well, but I guess it’s cause I made it a lot more complicated then it had to be.

I’ll take a look that example, thank you

I think the problem is having differend perspectives you have the component state (if a piece is picked up) and the game state The component (model+view+controller) can be the view of your ‘Model view controller’-bit of your game.

I think reading about the composite pattern might open up the way to some solutions.