程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA編程入門知識 >> java使用swt顯示圖片示例分享

java使用swt顯示圖片示例分享

編輯:JAVA編程入門知識

代碼如下:

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();
 }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved