import java.awt.Dimension;
import javax.swing.JFrame;
public class Window {
public Window(int width, int height, String title){
JFrame frame = new JFrame(title);
frame.setPreferredSize(new Dimension(width,height));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
public class Driver {
private final static int WIDTH = 500, HEIGHT = 500;
public static void main(String[] args) {
new Window(WIDTH,HEIGHT,"Title");
}
}
最佳答案
不要这样做 frame.setPreferredSize(new Dimension(width,height));
,而是尝试这样做。
frame.setSize(宽度,高度);
关于java - JFrame 不显示使用宽度和高度变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44341245/