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