juzhong.java~4~

来自「对2000元以上的资产管理」· JAVA~4~ 代码 · 共 76 行

JAVA~4~
76
字号
package com.util;

import javax.swing.JDialog;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2008</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class JuZhong {
  public JuZhong() {
  }

  /**
   * 此方法设置Frame居中及大小
   * @param frame JFrame
   * @param width int
   * @param height int
   */
  public static void showFrame(JFrame frame, int width, int height) {

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(width, height);
    // Center the window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height) {
      frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
      frameSize.width = screenSize.width;
    }
    frame.setLocation( (screenSize.width - frameSize.width) / 2,
                      (screenSize.height - frameSize.height) / 2);
    frame.setVisible(true);

  }

  /**
   * 此方法设置Dialog居中及大小
   * @param dialog JDialog
   * @param width int
   * @param heigth int
   */
  public static void showDialog(JDialog dialog, int width, int heigth) {
    dialog.setSize(width, heigth);
    dialog.setResizable(false); //窗体不可改变大小
    // Center the window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension dialogSize = dialog.getSize();
    if (dialogSize.height > screenSize.height) {
      dialogSize.height = screenSize.height;
    }
    if (dialogSize.width > screenSize.width) {
      dialogSize.width = screenSize.width;
    }
    dialog.setLocation( (screenSize.width - dialogSize.width) / 2,
                       (screenSize.height - dialogSize.height) / 2);

    dialog.setModal(true);
    dialog.setVisible(true);
  }

//  public static
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?