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

📄 imageloader.java

📁 一款JAVA款的跳棋
💻 JAVA
字号:
package org.yushang.jumpchess.image;


import java.io.IOException;
import java.io.InputStream;

import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.graphics.Rectangle;

public class ImageLoader {
	private Image image = null;
	private Rectangle rect = null;
	
	public ImageLoader(Display display, String string) {
		image = loadImage(display, ImageLoader.class, string);
		if (image == null) {
			throw new RuntimeException("ImageLoader[" + string + "] Error");
		}		
		rect  = image.getBounds();
	}
	
	public Rectangle getRect() {
		return rect;
	}
	
	public void Draw(GC gc, int x, int y, int Offset) {
		if (image != null) {
			gc.drawImage(image, 0, 0, rect.width, rect.height, 
					x - Offset, y - Offset, 
					rect.width + 2 * Offset, rect.height + 2 * Offset);
		}	
	}
	
	public static Image loadImage (Display display, Class clazz, String string) {
		InputStream stream = clazz.getResourceAsStream (string);
		if (stream == null) return null;
		Image image = null;
		try {
			image = new Image (display, stream);
		} catch (SWTException ex) {
		} finally {
			try {
				stream.close ();
			} catch (IOException ex) {}
		}
		return image;
	}
	public Image getImage() {
		return image;
	}
}

⌨️ 快捷键说明

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