




已阅读5页,还剩21页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package swt_jface.demo10; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class GCCreation Display display = new Display(); Shell shell = new Shell(display); public GCCreation() Image image = new Image(display, C:/icons/eclipse.gif); Image image2 = new Image(display, image.getImageData(); GC gc = new GC(image2); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE); gc.drawOval(10, 10, 90, 40); gc.dispose(); CLabel label = new CLabel(shell, SWT.NULL); label.setImage(image); label.setBounds(10, 10, 130, 130); CLabel label2 = new CLabel(shell, SWT.NULL); label2.setImage(image2); label2.setBounds(150, 10, 130, 130); shell.pack(); shell.open(); while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep(); display.dispose(); public static void main(String args) new GCCreation(); package swt_jface.demo10;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.CLabel;import org.eclipse.swt.graphics.GC;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class GCCreation Display display = new Display();Shell shell = new Shell(display);public GCCreation() Image image = new Image(display, C:/icons/eclipse.gif);Image image2 = new Image(display, image.getImageData();GC gc = new GC(image2);gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE);gc.drawOval(10, 10, 90, 40);gc.dispose();CLabel label = new CLabel(shell, SWT.NULL);label.setImage(image);label.setBounds(10, 10, 130, 130);CLabel label2 = new CLabel(shell, SWT.NULL);label2.setImage(image2);label2.setBounds(150, 10, 130, 130);shell.pack();shell.open();while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep();display.dispose();public static void main(String args) new GCCreation(); 接下来请参看以下示例:演示代码1:view plaincopy to clipboardprint?package swt_jface.demo10; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class CanvasExample Display display = new Display(); Shell shell = new Shell(display); public CanvasExample() Canvas canvas = new Canvas(shell, SWT.NULL); canvas.setBounds(10, 10, 200, 100); canvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) e.gc.drawRoundRectangle(10, 10, 180, 80, 10, 10); ); shell.pack(); shell.open(); while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep(); display.dispose(); public static void main(String args) new CanvasExample(); package swt_jface.demo10;import org.eclipse.swt.SWT;import org.eclipse.swt.events.PaintEvent;import org.eclipse.swt.events.PaintListener;import org.eclipse.swt.widgets.Canvas;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class CanvasExample Display display = new Display();Shell shell = new Shell(display);public CanvasExample() Canvas canvas = new Canvas(shell, SWT.NULL);canvas.setBounds(10, 10, 200, 100);canvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) e.gc.drawRoundRectangle(10, 10, 180, 80, 10, 10););shell.pack();shell.open();while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep();display.dispose();public static void main(String args) new CanvasExample(); 演示代码2:(三角)view plaincopy to clipboardprint?package swt_jface.demo10; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Region; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class Clipping Display display = new Display(); Shell shell = new Shell(display); public Clipping() shell.setLayout(new FillLayout(); final Canvas canvas = new Canvas(shell, SWT.NULL); final Image image = new Image(display, C:/icons/eclipse.gif); canvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) Region region = new Region(); region.add(new int60, 10, 10, 100, 110, 100); e.gc.setClipping(region); e.gc.drawImage(image, 0, 0); ); shell.setSize(200, 140); shell.open(); while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep(); display.dispose(); public static void main(String args) new Clipping(); package swt_jface.demo10;import org.eclipse.swt.SWT;import org.eclipse.swt.events.PaintEvent;import org.eclipse.swt.events.PaintListener;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.graphics.Region;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.widgets.Canvas;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class Clipping Display display = new Display();Shell shell = new Shell(display);public Clipping() shell.setLayout(new FillLayout();final Canvas canvas = new Canvas(shell, SWT.NULL);final Image image = new Image(display, C:/icons/eclipse.gif);canvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) Region region = new Region();region.add(new int60, 10, 10, 100, 110, 100);e.gc.setClipping(region);e.gc.drawImage(image, 0, 0););shell.setSize(200, 140);shell.open();while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep();display.dispose();public static void main(String args) new Clipping(); 演示代码3:(动态画布)view plaincopy to clipboardprint?package swt_jface.demo10; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class DoubleBuffer Display display = new Display(); Shell shell = new Shell(display); public DoubleBuffer() shell.setLayout(new FillLayout(); final Canvas canvas = new Canvas(shell, SWT.NULL); canvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) Point size = canvas.getSize(); int x1 = (int) (Math.random() * size.x); int y1 = (int) (Math.random() * size.y); int x2 = Math.max(canvas.getBounds().width - x1 - 10, 50); int y2 = Math.max(canvas.getBounds().height - y1 - 10, 50); e.gc.drawRoundRectangle(x1, y1, x2, y2, 5, 5); display.timerExec(100, new Runnable() public void run() canvas.redraw(); ); ); final Canvas doubleBufferedCanvas = new Canvas(shell, SWT.NO_BACKGROUND); doubleBufferedCanvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) Image image = (Image) doubleBufferedCanvas.getData(double-buffer-image); if (image = null | image.getBounds().width != doubleBufferedCanvas.getSize().x | image.getBounds().height != doubleBufferedCanvas.getSize().y) image = new Image( display, doubleBufferedCanvas.getSize().x, doubleBufferedCanvas.getSize().y); doubleBufferedCanvas.setData(double-buffer-image, image); GC imageGC = new GC(image); imageGC.setBackground(e.gc.getBackground(); imageGC.setForeground(e.gc.getForeground(); imageGC.setFont(e.gc.getFont(); Rectangle imageSize = image.getBounds(); imageGC.fillRectangle(0, 0, imageSize.width + 1, imageSize.height + 1); Point size = doubleBufferedCanvas.getSize(); int x1 = (int) (Math.random() * size.x); int y1 = (int) (Math.random() * size.y); int x2 = Math.max(doubleBufferedCanvas.getBounds().width - x1 - 10, 50); int y2 = Math.max(doubleBufferedCanvas.getBounds().height - y1 - 10, 50); imageGC.drawRoundRectangle(x1, y1, x2, y2, 5, 5); e.gc.drawImage(image, 0, 0); imageGC.dispose(); display.timerExec(100, new Runnable() public void run() doubleBufferedCanvas.redraw(); ); ); shell.setSize(300, 200); shell.open(); while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep(); display.dispose(); public static void main(String args) new DoubleBuffer(); package swt_jface.demo10;import org.eclipse.swt.SWT;import org.eclipse.swt.events.PaintEvent;import org.eclipse.swt.events.PaintListener;import org.eclipse.swt.graphics.GC;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.graphics.Rectangle;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.widgets.Canvas;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class DoubleBuffer Display display = new Display();Shell shell = new Shell(display);public DoubleBuffer() shell.setLayout(new FillLayout();final Canvas canvas = new Canvas(shell, SWT.NULL);canvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) Point size = canvas.getSize();int x1 = (int) (Math.random() * size.x);int y1 = (int) (Math.random() * size.y);int x2 = Math.max(canvas.getBounds().width - x1 - 10, 50);int y2 = Math.max(canvas.getBounds().height - y1 - 10, 50);e.gc.drawRoundRectangle(x1, y1, x2, y2, 5, 5);display.timerExec(100, new Runnable() public void run() canvas.redraw();););final Canvas doubleBufferedCanvas = new Canvas(shell, SWT.NO_BACKGROUND);doubleBufferedCanvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) Image image = (Image) doubleBufferedCanvas.getData(double-buffer-image);if (image = null| image.getBounds().width != doubleBufferedCanvas.getSize().x| image.getBounds().height != doubleBufferedCanvas.getSize().y) image =new Image(display,doubleBufferedCanvas.getSize().x,doubleBufferedCanvas.getSize().y);doubleBufferedCanvas.setData(double-buffer-image, image);GC imageGC = new GC(image);imageGC.setBackground(e.gc.getBackground();imageGC.setForeground(e.gc.getForeground();imageGC.setFont(e.gc.getFont();Rectangle imageSize = image.getBounds();imageGC.fillRectangle(0, 0, imageSize.width + 1, imageSize.height + 1);Point size = doubleBufferedCanvas.getSize();int x1 = (int) (Math.random() * size.x);int y1 = (int) (Math.random() * size.y);int x2 = Math.max(doubleBufferedCanvas.getBounds().width - x1 - 10, 50);int y2 = Math.max(doubleBufferedCanvas.getBounds().height - y1 - 10, 50);imageGC.drawRoundRectangle(x1, y1, x2, y2, 5, 5);e.gc.drawImage(image, 0, 0);imageGC.dispose();display.timerExec(100, new Runnable() public void run() doubleBufferedCanvas.redraw();););shell.setSize(300, 200);shell.open();while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep();display.dispose();public static void main(String args) new DoubleBuffer(); 演示代码4:(图片)view plaincopy to clipboardprint?package swt_jface.demo10; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.ImageLoader; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class DrawImages Display display = new Display(); Shell shell = new Shell(display); public DrawImages() shell.setLayout(new FillLayout(); Canvas canvas = new Canvas(shell, SWT.NULL); final Image image = new Image(display, C:/icons/eclipse.gif); canvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) e.gc.drawImage(image, 10, 10); e.gc.drawImage(image, 0, 0, 100, 100, 200, 10, 200, 50); ); shell.setSize(430, 200); shell.open(); captureControl(canvas, canvas.bmp); while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep(); display.dispose(); public static void captureControl(Control control, String file) GC gc = new GC(control); Image image = new Image(control.getDisplay(), control.getSize().x, control.getSize().y); gc.copyArea(image, 0, 0); ImageLoader loader = new ImageLoader(); loader.data = new ImageData image.getImageData() ; loader.save(file, SWT.IMAGE_BMP); gc.dispose(); public static void main(String args) new DrawImages(); package swt_jface.demo10;import org.eclipse.swt.SWT;import org.eclipse.swt.events.PaintEvent;import org.eclipse.swt.events.PaintListener;import org.eclipse.swt.graphics.GC;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.graphics.ImageData;import org.eclipse.swt.graphics.ImageLoader;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.widgets.Canvas;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class DrawImages Display display = new Display();Shell shell = new Shell(display);public DrawImages() shell.setLayout(new FillLayout();Canvas canvas = new Canvas(shell, SWT.NULL);final Image image = new Image(display, C:/icons/eclipse.gif);canvas.addPaintListener(new PaintListener() public void paintControl(PaintEvent e) e.gc.drawImage(image, 10, 10);e.gc.drawImage(image, 0, 0, 100, 100, 200, 10, 200, 50););shell.setSize(430, 200);shell.open();captureControl(canvas, canvas.bmp);while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep();display.dispose();public static void captureControl(Control control, String file) GC gc = new GC(control);Image image = new Image(control.getDisplay(), control.getSize().x, control
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年工程师入职考试模拟题集机电工程专业知识
- 2025年医生中级专业面试问题及答案
- 2025年国际贸易实务初级模拟题集
- 【教案版】小学六班级上册 软式排球3
- 2025年财务管理实务操作面试技巧与预测题
- 中班找梦教学课件
- 2025年烈士纪念场所工作人员岗位胜任力面试题及参考答案
- 2025年初中体育教师招聘考试高频考点预测题
- 2025年酒店行业招聘考试模拟题及面试技巧指南手册
- 儿童彩铅教学课件
- 《政治经济学》(全套课件)
- 武汉理工大学计算机科学与技术学院课程教学大纲
- 应急疏散培训试题
- 开学安保工作方案(6篇)
- QC080000-2017 HSF有害物质管理程序文件全套
- 计量操作人员(通用类)考试题库(含答案)
- 大海(张雨生)原版五线谱钢琴谱正谱乐谱
- 公开课第一课素描基础入门课件
- 数据结构ppt课件完整版
- 铝模板施工工艺标准
- 采购与供应管理(二)教案
评论
0/150
提交评论