独自のフォームを作成

1315 ワード

import java.awt.Toolkit;
import javax.swing.*;
import java.awt.*;
/**
 *  
 * @author fan
 *
 */
public class MyMainFrame extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 *  : , 
	 * @param sTitle  
	 * @param width  
	 * @param height  
	 */
	public MyMainFrame(String sTitle, int width, int height){
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		ImageIcon ii = new ImageIcon(this.getClass().getClassLoader().getResource("base2011/images/middle.gif"));
		setTitle(sTitle);
		// 
		setIconImage(ii.getImage());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(width, height);
		int w = getSize().width;
		int h = getSize().height;
		System.out.println(" :"+w+" :"+h);
		int x = (dim.width - w)/2;
		int y = (dim.height - h)/2;
		// 
		setLocation(x, y);
		setVisible(true);
	}
	/**
	 *  
	 * @param args
	 */
	public static void main(String[] args){
		JFrame.setDefaultLookAndFeelDecorated(false);
		new MyMainFrame("Main Frame", 300, 400);
	}
}