中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > JavaScripts > 综合文章
JFrame基类(简化BorderLayout的add方法)
作者:佚名 时间:2005-03-07 11:03 出处:互连网 责编:chinaitpower
              摘要:JFrame基类(简化BorderLayout的add方法)

/**
** This program is free software.
**
** You may redistribute it and/or modify it under the terms of the GNU
** General Public License as published by the Free Software Foundation.
** Version 2 of the license should be included with this distribution in
** the file LICENSE, as well as License.html. If the license is not
** included with this distribution, you may find a copy at the FSF web
** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
**
** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
** REDISTRIBUTION OF THIS SOFTWARE.
**/

package kindani.gui;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.text.*;



/**
 * 所有JFrame的基类。
 * 有一个标题为参数的构造函数。
 * 缺省关闭操作为系统退出。
 * 缺省的L&F为操作系统的L&F。
 * created at 2002/10/12
 * modified at
 */

public class JxFrame extends JFrame {


    public JxFrame() {
        this("");
    }


    public JxFrame(String title) {
        super(title);
        setCloseClick();
        setLF();
    }


    /**缺省关闭操作为系统退出。*/
    private void setCloseClick() {
        //create window listener to respond to window close click
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
    //------------------------------------------
    /**缺省的L&F为操作系统的L&F。*/
    private void setLF() {
        // Force SwingApp to come up in the System L&F
        String laf = UIManager.getSystemLookAndFeelClassName();
        try {
            UIManager.setLookAndFeel(laf);
        } catch (UnsupportedLookAndFeelException exc) {
            System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
        } catch (Exception exc) {
            System.err.println("Error loading " + laf + ": " + exc);
        }
    }


    /**
     * 使frame最大化
     */
    protected void setMaximizeSize() {
        setSize(GUIUtil.getScreenWidth(), GUIUtil.getScreenHeight());
    }


    /**
     * 指定frame的尺寸,并使frame居中
     * @param width frame的宽度
     * @param height frame的高度
     */
    public void centerWindow(int width, int height) {
        setSize(width, height);
        setLocation((GUIUtil.getScreenWidth() - width) / 2,
                (GUIUtil.getScreenHeight() - height) / 2);
    }


    public void addNorth(Component c) {
        getContentPane().add(c, BorderLayout.NORTH);
    }


    public void addCenter(Component c) {
        getContentPane().add(c, BorderLayout.CENTER);
    }


    public void addSouth(Component c) {
        getContentPane().add(c, BorderLayout.SOUTH);
    }


    public void addWest(Component c) {
        getContentPane().add(c, BorderLayout.WEST);
    }


    public void addEast(Component c) {
        getContentPane().add(c, BorderLayout.EAST);
    }


}

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有