首先想到的主要用的方法,是:
java.awt.JFrame.setSize(int width, int height);
java.awt.JFrame.setLocation(int x, int y);
而获取屏幕尺寸信息,一定要用到:
static Toolkit.getDefaultToolkit();
Toolkit.getScreenSize();
而呈现出这样一个框架自然要用到其构造函数,并设置它可见:
JFrame.JFrame();
JFrame.setVisible(boolean flag);
package com.sinosuperman.driver;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class MainBench {
public static void main(String[] args) {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setSize((int) d.getWidth() / 2, (int) d.getHeight() / 2);
frame.setLocation((int) (d.getWidth() - frame.getWidth()) / 2, (int) (d.getHeight() - frame.getHeight()) / 2);
frame.setResizable(false);
frame.setVisible(true);
}
}
分享到:
2011-11-20 19:16
浏览 151
评论