RISK GUI component higherarchies

I have also posted the same question in the Applet section. Sorry for the repost but I didn't know where to post this question. Thanks for your time!

I am trying to make a game of Risk (The world domination board game). My design has a gamePanel that extends JPanel and has children attackPanel and placePanel. The idea is that when the user clicks the radio buttons in a seperate panel (by the way this panel works fine and the buttons can be clicked) the gamePanel intance named board will polymophically change from type gamePanel, attackPanel, or placePanel to, depeding on the button clicked, placePanel or attackPanel. To debug I tried having gamePanel have its paintComponent class paint a green square, the attackPanel paint a red square, and the placePanel print a white square. I don't have the code with me now, but the radio button's listener method looked something like this in psedo-code.

//class variables

gamePanel board;

attackPanel aBoard;

placePanel pBoard;

//Method name parameters etc...

{

if (attack mode was clicked)

{

board=aBoard;

}

if(place mode was clicked)

{

board=pBoard;

}

repaint()

}

At one point i also had board.repaint() but that just made the whole applet redo its self in the board component. At another time I had the green square displaying (board of type gameBoard) and clicking wouldn't change that, but now I have only a gray background and when I click the radio buttons nothin changes at all. Help would be greatly appriciated, thanks!

[1614 byte] By [Robertlkt] at [2007-9-30 7:26:59]
# 1

Sorry to spam my own thread, but I am at school where my code is now and can post it.

public class gamePanel extends JPanel

{

//private variables etc...

public gamePanel()

{

}

public void paintComponent (Graphics page)

{

super.paintComponent(page);

page.setColor(Color.green);

page.fillRect(100,100,500,500);

}

//other methods not shown

}

public class placePanel extends gamePanel

{

public placePanel()

{

}

public void paintComponent (Graphics page)

{

super.paintComponent(page);

page.setColor(Color.white);

page.fillRect(100,100, 500, 500);

}

}

public class attackPanel extends gamePanel

{

public attackPanel()

{

}

public void paintComponent (Graphics page)

{

super.paintComponent(page);

page.setColor(Color.red);

page.fillRect(100,100, 500, 500);

}

}

//This is the driver applet that uses all the components. This is a code segment at the end of the class

...

board = new gamePanel ();

aBoard = new attackPanel();

pBoard = new placePanel();

appletPanel = new JPanel();

appletPanel.setLayout(new BoxLayout (appletPanel, BoxLayout.Y_AXIS));

appletPanel.add (tools);

appletPanel.add (board);

getContentPane().add (appletPanel);

}

//Subclass that listens to the radio buttons in the tools Component

//--

// Determines which button was pushed, and either changes the mode

// or ends the turn of the player.

//--

public void actionPerformed (ActionEvent event)

{

//buttons being pushed

if (event.getSource()==attackMode)

{

board=aBoard;

}

else if (event.getSource()==addUnitsMode)

{

board=pBoard;

}

else if (event.getSource()==done)

{

board.nextTurn();

}

board.repaint();

}

This will display a green rectangle, but clicking the radio buttons does nothing. Is the repaint()method in the wrong place? Please help me understand why the polymorphism isn't making the different color rectangles display when I click different buttons!?!?

Robertlkt at 2007-7-2 0:08:09 > top of Java-index,Other Topics,Java Game Development...
# 2
please click the link above the text field before your next post and read about Formatting Help.
Malohkan at 2007-7-2 0:08:09 > top of Java-index,Other Topics,Java Game Development...