posted 21 years ago
Hello People,
I'm trying to write a game that invloves placing a piece on a "board" and then doing stuff to it, like moving it about etc.. I would like to have a grahic that is independent of the board, but I don't know how to do this. At the moment, I have a piece that I place on the board, but I've done it with a polygon, which is part of the board, by definition. My code looks something like this (off the top of my head..)
public class board extends JPanel
{
public board()
{
//constructor stuff..
}
public void paintComponent(Graphics g)
{
g.setColor(Color.black);
g.fillRect(200,400);
int [] x = {x1, x2, x3, x4}
int [] y = {y1, y2, y3, y4}
Polygon p = new Polygon(x, y, 4);
g.setColor(Color.white);
g.fillPolygon(p);
}
//more code that does other stuff..
}
I basically want something that I can place anywhere I like, and then move or rotate it, etc.. I reckon it would be better to have something independent of the JPanel so I could then put it in a different class and manipulate it independently if I want to.
Any help would, of course, be greatly appreciated!
Cheers,
Malcolm