Posted By:
John_Starr
Posted On:
Friday, June 4, 2004 08:03 AM
Please help. 100% homework question here so please do not respond if that bothers you. I have a JFrame with two JPanels added to it. I have several Objects that extend Rectangle2D.Double and Ellipse2D.Double that I want to show on one of the JPanels. How do I do this? I have tried everything I can think of. My JPanel is this: public class Board extends JPanel { private Square[][] boardMap; int grid = 8; private Square newSquare; private Checker oneChecker; public Board(){ boardMap = new Square[8][8]; initializeBoard(); }//End Const public void initializeBoard(){ //Sets up the board
More>>
Please help. 100% homework question here so please do not respond if that bothers you.
I have a JFrame with two JPanels added to it. I have several Objects that extend Rectangle2D.Double and Ellipse2D.Double that I want to show on one of the JPanels.
How do I do this? I have tried everything I can think of.
My JPanel is this:
public class Board extends JPanel {
private Square[][] boardMap;
int grid = 8;
private Square newSquare;
private Checker oneChecker;
public Board(){
boardMap = new Square[8][8];
initializeBoard();
}//End Const
public void initializeBoard(){
//Sets up the board for the first move
boardMap[0][0] = new Square();
}//End initializeBoard
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
//g2d.setColor(Color.RED);
//g2d.fill(new Rectangle2D.Double(50, 50, 50, 50));
}//End paintComponent
}//End Class
My Rectangle2D child is this:
public class Square extends Rectangle2D.Double {
private static int numSquares = 0;
private boolean isOccupied;
private Color color;
private Object piece; //Reference to the playing
//piece currently on this Square
private Point2D centerSquare;
public Square(){
super(100,100,50,50);
color = Color.RED;
//Keep track of the total number of squares
numSquares ++;
//Alternate their color as you build them
if(numSquares%2 == 0){
this.color = Color.red;
}
else{
this.color = Color.LIGHT_GRAY;
}//End if
}//End Const
public Color getColor(){
return color;
}//End getColor
public void setColor(Color c){
this.color = c;
}//End setColor
public boolean isOccupied(){
boolean flag = false;
if(isOccupied == true){
flag = true;
}//End if
return flag;
}//End isOccupied
public void setOccupied(){
isOccupied = true;
}//End setOccupied
}//End Class
If you are my Professor, please forgive me :-)
Thanks
<<Less