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

📄 util.java

📁 本文首先介绍了这些考试系统的形成和发展过程
💻 JAVA
字号:
package net.robin.crm.util;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Util {
	
	public static final String PHOTO_PATH="photo"; 
	
	private static int photoHeight = 214; 
	private static int photoWidth = 150; 

	
	public static JFrame application;

	private Util() {
		super();
		// TODO 自动生成构造函数存根
	}
	
	
	public static JFrame getApplication() {
		return application;
	}


	public static void setApplication(JFrame application) {
		Util.application = application;
	}


	public static void message(String message){
		JOptionPane.showMessageDialog(application, message, "系统信息", JOptionPane.INFORMATION_MESSAGE);
	}
 
	
	public static void warning(String message){
		JOptionPane.showMessageDialog(application, message, "系统信息", JOptionPane.WARNING_MESSAGE);		
	}
	
	
	public static void error(String message){
		JOptionPane.showMessageDialog(application, message, "系统错误", JOptionPane.ERROR_MESSAGE);
	}
 
	public static URL getPhotoURL(String photo){
		URL url = Util.class.getResource("/net/robin/crm/ui/mk.jpg");
		if(photo==null || photo.equals(""))
			return url;
		
		//String photoPath = getConfig().getProperty("photo.path");
		
		String photoPath = PHOTO_PATH;
		
		File photoFile = new File(photoPath+File.separator+photo );
		try {
			if( photoFile.isFile() && photoFile.exists())
				url = photoFile.toURL();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		return url;
	}
	
	public static BufferedImage loadPhoto(String photo) throws IOException{
		if(photo==null || photo.trim().equals("")){
			return null;
		}
		return ImageTools.readImage(PHOTO_PATH
				+ File.separator + photo );
	}
	
	public static BufferedImage loadPhoto(File file) throws IOException{
		return ImageTools.readImage(file);
	}
	
	public static BufferedImage resizePhoto(BufferedImage photo){
		return ImageTools.thumbFilter(photo, photoWidth, photoHeight);
	}
	
	public static String savePhoto(BufferedImage photo) throws IOException{
		String name = System.currentTimeMillis() + "." + ImageTools.PNG;
		String path = PHOTO_PATH + File.separator;
		ImageTools.writeImage(photo, path + name);
		
		return name;
	}
	
	
	public static boolean removePhoto(String photo) throws IOException{
		File file = new File(  PHOTO_PATH + File.separator + photo);
		if(file.exists()){
			file.delete();
			return true;
		}
		return false;
	}
	
	public static void centerWindow(Window window){
		Dimension screen  = Toolkit.getDefaultToolkit().getScreenSize();
		Point location = new Point();
		
		location.x = (screen.width - window.getWidth())/2;
		location.y = (screen.height - window.getHeight())/2;
		
		window.setLocation(location); 
	}

}

⌨️ 快捷键说明

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