⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolkit.java

📁 员工管理系统 在一个公司里员工之间都有工作上的联系。对方的联系方式
💻 JAVA
字号:
package com.tool;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.Component;

/**
 * 工具包类,提供了常用的静态工具方法
 * <br>
 * 比如:测试字符串是否为空
 * <br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 * 测试字符串是否为int数据<br>
 * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 * 测试字符串是否为自定的正则表达式
 * 
 */
public class ToolKit {

    /**
     * 获取制定窗口位于屏幕中心位置的坐标
     *
     * @param size 窗口大小
     * @return 中心位置坐标
     */
	public static Point getScreenCenterLocation(Dimension size) {
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Dimension screenSize = toolkit.getScreenSize();
                if (screenSize.width<size.width) size.width=screenSize.width;
                if (screenSize.height<size.height) size.height=screenSize.height;
		Point location = new Point();
		location.x = ( screenSize.width - size.width )/ 2;
		location.y = ( screenSize.height - size.height )/ 2;
		return location;
	}

    /**
     * 获取相对指定组件居中的位置
     *
     * @param size 要居中的组件尺寸
     * @param owner 获取相对坐标的组件
     * @return 居中位置的坐标
     */
    public static Point getComponentCenterLocation(Dimension size, Component owner){
        Point location = new Point();
        int centerX = owner.getX() + owner.getWidth() / 2;
        int centerY = owner.getY() + owner.getHeight() / 2;
        location.x = centerX - size.width / 2;
        location.y = centerY - size.height / 2;
        return location;
    }

    /**
     * 检查字符串是否有空格
     *
     * @param str 要检查的字符串
     * @return true 当包含空格时
     */
    public static boolean hasSpace(String str) {
        if (str.indexOf(" ") != -1) {
            return true;
        }
        return false;
    }

    public static boolean matchRegex(String string, String info, String regex) {
        if(string.matches(regex)){
            return true;
        }
        return false;
    }

    public static boolean isNull(String str) {
        if (str == null | str.equals("")) {
            return true;
        }
        return false;
    }

    public static boolean isInt(String numStr){
        try{
            Integer.parseInt(numStr);
            return true;
        }
        catch(NumberFormatException ex){
            return false;
        }
    }
}

⌨️ 快捷键说明

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