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