0

ここにJFrameがあります:

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() {

    }
}

そしてこれArenaは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));
    }
}

それでも、JFrame のサイズは 0 x 0 になります。

4

2 に答える 2

2

コンストラクターの命令setLayout(null);を削除する必要があります。Game

于 2012-08-13T16:09:52.497 に答える
0

たぶんsetSize(600, 600);、コンストラクターで他のすべての修正を行っている場所でできますか?

于 2012-08-13T15:48:29.537 に答える