public class GameFrame extends Frame {
public void launchFrame() {
this.setSize(500, 500);
this.setLocation(200, 100);
this.setResizable(false);
// 缺少 this.setVisible(true);
}
public static void main(String[] args) {
new GameFrame().launchFrame();
}
}
public void launchFrame() {
this.setSize(500, 500);
this.setLocation(200, 100);
this.setResizable(false);
this.setVisible(true); // 必須顯式設定可見
}
Frame 預設 visible = false,需呼叫 setVisible(true) 才會在螢幕繪製。JFrame 替代 Frame,並遵循 EDT 執行緒:SwingUtilities.invokeLater(() -> {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500, 500);
f.setVisible(true);
});