[英]Java : Did i do something wrong when i added this panel?
我在中間創建pong,不確定是否做錯了什么。 如果錯誤與框架無關,請告訴我。
public class PongFrame extends JFrame {
PongFrame(){
super("PONG");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(600,400);
this.setVisible(true);
this.setResizable(false);
this.setLocation(450,200);
setLayout(new BorderLayout());
PongPanel panel = new PongPanel();
add(panel, BorderLayout.CENTER);
}
}
您正在調用this.setVisible(true);
在完成GUI的構造之前,應盡可能先調用此函數
public class PongFrame extends JFrame {
PongFrame(){
super("PONG");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
setLayout(new BorderLayout());
PongPanel panel = new PongPanel();
add(panel, BorderLayout.CENTER);
this.setSize(600,400);
this.setLocation(450,200);
this.setVisible(true);
}
}
您還應該依賴JFrame#pack
而不是setSize
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.