import java.awt.Dimension;
import javax.swing.*;
public class Game extends JFrame {
private static final long serialVersionUID = -7919358146481096788L;
JPanel a = new JPanel();
public static void main(String[] args) {
new Game();
}
private Game() {
setTitle("Insert name of game here");
setLocationRelativeTo(null);
setLayout(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
a.setPreferredSize(new Dimension(600, 600));
add(a);
pack();
setVisible(true);
}
}
所以我用600集的JPanel
的首选尺寸600和包装的框架,但帧的大小仍然是0 0.
为什么这和我该如何解决它?
参见:[?为什么不赞成使用在Swing空布局(http://stackoverflow.com/questions/6592468/why-is-它皱起了眉头,使用一个null-layout-in-swing) – 2012-08-13 17:28:27