📄 toolkit.java
字号:
package com.ciash.common.gui.tool;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.Component;
/**
* 工具包类,提供了常用的静态工具方法
* <br>
* 比如:测试字符串是否为空
* <br>
*
* 测试字符串是否为int数据<br>
*
* 测试字符串是否为自定的正则表达式
*
*/
public class ToolKit {
/**
* 获取制定窗口位于屏幕中心位置的坐标
*
* @param size 窗口大小
* @return 中心位置坐标
*/
public static Point getScreenCenterLocation(Dimension size) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Point location = new Point();
location.x = screenSize.width / 2 - size.width / 2;
location.y = screenSize.height / 2 - 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 + -