java使用swt显示图片示例分享
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:importorg.eclipse.swt.graphics.GC;importorg.eclipse.swt.graph...
复制代码 代码如下:
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ImagesHelloWorld {
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell();
Image image = new Image(display, "c://c240b2dcc132c9c6.jpg");
shell.setText("ImageReader");
shell.setImage(image);
Rectangle bounds = image.getBounds();
shell.setSize(bounds.width + 15, bounds.height +15);
shell.open();
GC gc = new GC(shell);
gc.drawImage(image,5,5);
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}