java使用swt显示图片示例分享
程序员文章站
2024-02-22 07:58:46
复制代码 代码如下:import org.eclipse.swt.graphics.gc;import org.eclipse.swt.graphics.image;imp...
复制代码 代码如下:
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();
}
}