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

📄 imagedemo.java

📁 java图形界面开发
💻 JAVA
字号:
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class ImageDemo {

	public static Display myDisplay;
	public static boolean internalCall = false;

	public static void main(String[] args) {
		internalCall = true;
		myDisplay = new Display();
		ImageDemo id = new ImageDemo();
		id.runDemo(myDisplay);
	}
	
	public void runDemo(Display display) {
		myDisplay = display;
		Shell shell = new Shell(display);
		shell.setSize(140,100);
		shell.setText("Image Demo");

		//load an image from a JPEG file
		Image img = new Image(display, "EclipseBannerPic.jpg");		

//		//roughly equivalent code that works for loading an image from a JAR file
//		InputStream is = getClass().getResourceAsStream("EclipseBannerPic.jpg");
//		Image img = new Image(display, is);
		
		//open the shell, so we can draw on it
		shell.open();

		//get a Graphics Context
		GC gc = new GC(shell);
		
		//draw the image at a specific x and y location
		gc.drawImage(img, 0, 0);
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		
		//dispose of the image object
		img.dispose();

		if (internalCall) display.dispose();

	}
	
}

⌨️ 快捷键说明

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