Setting the JFrame size for my Maze
G'day Guys,
I'm having trouble setting the size of my main JFrame appropriatly for my Maze. I am generating a maze by creating a series of lines in my DrawMaze class (which extends JPanel):
g2d.draw(new Line2D.Double(x, y, x, y)
This works fine. I then go to sick it in a JFrame in my main class:
Container c = DrawMaze(x, y, cells);
jf.setContentPane(c);
jf.setSize((x * 10), (y * 10));// each cell is 10 by 10;
However this approach of sizing will set the JFrame too small (if it's a small maze) or too large (if it's a large Maze). Getting the preferred size of the container does not work either.
Here are some code snippets to clarify things a little better.
Remember, these are only snippets, if it looks like something isn't being defined or closed, thats because it is being defined/closed else where.
DrawMaze.java
publicvoid paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
for(int x = 0; x < length; x++){
for(int y = 0; y < height; y++){
if(cells[x][y].getWallStatus(1)){
double s = 10 * x;
double e = 10 * y;
g2d.draw(new Line2D.Double(s, e, (s + 10), e));
}
Repeat for wallStatus 2-4 (in the same for loops).
TestMain.java
publicstaticvoid main(String[] argv){
Maze m =new Maze(10,10);
x = m.getLength();
y = m.getHeight();
int size = x * y;
Container content =new DrawMaze(x, y, m.getCells());
JFrame jf =new JFrame("Test");
jf.setSize((x * 11), (y * 11));
jf.setContentPane(content);
jf.setVisible(true);
}
Any Suggestions would be greatly appreciated.

