Java card game
class duuzenden
{
GameStatus game; // contains all the hands, the score, etc
CardPanel myhandpanel,hishandpanel;
main{
myhandpanel = new CardPanel (spel.myhand);
hishandpanel = new CardPanel (spel.hishand);
}
void submit ()
// send Main.game
void receive ()
// receive a game and put it into Main.game
}
class GameStatus
{
Hand myhand, hishand, etc..
}
class CardPanel extends JPanel
{
Hand h;
CardPanel(Hand h)
this.h = h;
paintComponent(Graphics g)
g.draw(h);
}
The problem now is that the information about the cards I have is stored in two places (Main.game.myhand and myhandpanel.h). When the cards change, I have to change them in two places: in Main.game.myhand to send Main.game to the other player, and in myhandpanel.h for correct display. How can I remove this redundency?
I'd rather give the CardPanel some kind of reference to the Main.myhand and Main.hishand, so that it'd look like
class CardPanel extends JPanel
{
Hand *h;
CardPanel(*Hand h)
this.h = h;
paintComponent(Graphics g)
g.draw(&h);
}
so that each instance of the CardPanel class still manipulates the objects in Main.game.
Thanks for your help!
Ciro.

