打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
SWT之Canvas绘图
[java] view plaincopyprint?
  1. import org.eclipse.swt.SWT;  
  2. import org.eclipse.swt.events.PaintEvent;  
  3. import org.eclipse.swt.events.PaintListener;  
  4. import org.eclipse.swt.graphics.Image;  
  5. import org.eclipse.swt.layout.FormLayout;  
  6. import org.eclipse.swt.widgets.Canvas;  
  7. import org.eclipse.swt.widgets.Display;  
  8. import org.eclipse.swt.widgets.Shell;  
  9. public class ddd {  
  10.     protected Shell shell;  
  11.     private Canvas can;  
  12.     private final Image img = new Image(this.display, 'pic_1.png');  
  13.     private Display display;  
  14.     public static void main(String[] args) {  
  15.         try {  
  16.             ddd window = new ddd();  
  17.             window.open();  
  18.         } catch (Exception e) {  
  19.             e.printStackTrace();  
  20.         }  
  21.     }  
  22.     public void open() {  
  23.         createContents();  
  24.         this.can.addPaintListener(new PaintListener() {  
  25.             public void paintControl(PaintEvent e) {  
  26.                 can.setBounds(0,0,200,200);  
  27.                 e.gc.drawImage(img, 00);  
  28.             }  
  29.         });  
  30.         shell.open();  
  31.         while (!shell.isDisposed()) {  
  32.             if (!display.readAndDispatch()) {  
  33.                 display.sleep();  
  34.             }  
  35.         }  
  36.         this.display.dispose();  
  37.     }  
  38.     /** 
  39.      * Create contents of the window. 
  40.      */  
  41.     protected void createContents() {  
  42.         this.display = Display.getDefault();  
  43.         System.out.println(this.display.getBounds());  
  44.         shell = new Shell();  
  45.         shell.setLayout(new FormLayout());  
  46.         shell.setText('SWT Application');  
  47.         this.can = new Canvas(shell, SWT.BORDER);  
  48.         can.setBackground(display.getSystemColor(SWT.COLOR_GREEN));  
  49.     }  
  50. }  
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
SWT实现弹出日历控件
一个在windows和基于SWT的java程序间拖拽的例子(外部文件拖曳到SWT)
Java实现类MSN、QQ好友上线通知界面
Eclise Rcp 系列一 第一个SWT程序
SWT/JFace开发入门指南(笔记)
在awt/swing程序中添加swt (Browser控件的使用)【转】 - Picses...
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服