首页 >> 电子商务大学 >> 网站建设班 >> NET区
 
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);
    }

}




1
 
电子商务大学版权与免责声明:

 
凡本网注明“来源:35DX”的所有作品,版权均属于电子商务大学,未经本网授权不得转载、摘编或利用其它方式使用上述作品。已经本网授权使用作品的,应在授权范围内使用,并注明“来源:电子商务大学”。违反上述声明者,本网将追究其相关法律责任。
凡本网注明“来源:XXX(非电子商务大学)”的作品,均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,同时,本站转载并无任何商业目的。
如因作品内容、版权和其它问题需要同本网联系的,请在30日内进行。
联系方式:电子商务大学 webMaster@35dx.com