JFrame基类(简化BorderLayout的add方法)

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

/**

** 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);

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航