在下面这个程序中System.out.println(frame.WIDTH); System.out.println(frame.HEIGHT);两句系统为什么会输出1和2.这个不明白?
import javax.swing.*;
import java.awt.*;
public class CenterFrame {
public static void main(String args[]){
JFrame frame =new JFrame("Test centerFrame");
frame.setSize(400,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Get the dimension of the screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
//Get the dimension of the frame
Dimension frameSize = frame.getSize();
int x = (screenWidth - frameSize.width)/2;
int y = (screenHeight-frameSize.height)/2;
System.out.println(frame.WIDTH);
System.out.println(frame.HEIGHT);
frame.setLocation(x, y);
}
}