【JAVASwing】根据显示器分辨率大小生成消息框

package SizedFrame;

import java.awt.*;

import javax.swing.*;

public class SizedFrameTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				SizedFrame frame = new SizedFrame();
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.setVisible(true);
			}
		});
	}

}
class SizedFrame extends JFrame
{
	public SizedFrame()
	{
		//get screen dimension
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int screenHeight = (int) screenSize.getHeight();
		int screenWidth = (int) screenSize.getWidth();
		
		//set frame width,height and location
		
		setSize(screenWidth/2,screenHeight/2);
		setLocationByPlatform(true);
		
		//set frame icon and title
		
		Image img = kit.getImage("icon.gif");
		setIconImage(img);
		setTitle("SizedFrame");
		
		
	}
}

你可能感兴趣的:(【JAVASwing】根据显示器分辨率大小生成消息框)