0

I have a JFrame here:

import javax.swing.JFrame;

public class Game extends JFrame {
    private static final long serialVersionUID = -7919358146481096788L;
    Arena a = new Arena();
    public static void main(String[] args) {
        new Game();
    }
    private Game() {
        setTitle("Insert name of game here");
        setLocationRelativeTo(null);
        setLayout(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        add(a);
        pack();
        setResizable(false);
        setVisible(true);
    }
    private void refresh() {

    }
}

And the Arena is a JPanel:

import java.awt.Dimension;

import javax.swing.JPanel;

public class Arena extends JPanel {
    private static final long serialVersionUID = 6499922741928110264L;
    byte[][] world = new byte[6000][2000];
    int blockPix = 20;
    int x = 2999 * blockPix, y = 999 * blockPix;
    public Arena() {
        setLayout(null);
        setMinimumSize(new Dimension(600, 600));
        setMaximumSize(new Dimension(600, 600));
        setPreferredSize(new Dimension(600, 600));
    }
}

Yet the JFrame's size winds up being 0 by 0!

mKorbel
  • 109,525
  • 20
  • 134
  • 319
tckmn
  • 57,719
  • 27
  • 114
  • 156

2 Answers2

2

You should remove the instruction setLayout(null); in the Game constructor.

gontard
  • 28,720
  • 11
  • 94
  • 117
0

Maybe you could just setSize(600, 600); where you are doing all the other fixing up in your constructor?

ryebread761
  • 705
  • 1
  • 7
  • 14
  • no, because the title bar of the frame and all of the decorations are included and it just doesn't work. – tckmn Aug 13 '12 at 15:49