画布图形实例Word文件下载.docx

上传人:b****6 文档编号:20505205 上传时间:2023-01-23 格式:DOCX 页数:36 大小:20.31KB
下载 相关 举报
画布图形实例Word文件下载.docx_第1页
第1页 / 共36页
画布图形实例Word文件下载.docx_第2页
第2页 / 共36页
画布图形实例Word文件下载.docx_第3页
第3页 / 共36页
画布图形实例Word文件下载.docx_第4页
第4页 / 共36页
画布图形实例Word文件下载.docx_第5页
第5页 / 共36页
点击查看更多>>
下载资源
资源描述

画布图形实例Word文件下载.docx

《画布图形实例Word文件下载.docx》由会员分享,可在线阅读,更多相关《画布图形实例Word文件下载.docx(36页珍藏版)》请在冰豆网上搜索。

画布图形实例Word文件下载.docx

);

Imageimage2=newImage(display,image.getImageData());

GCgc=newGC(image2);

gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));

gc.drawOval(10,10,90,40);

gc.dispose();

CLabellabel=newCLabel(shell,SWT.NULL);

label.setImage(image);

label.setBounds(10,10,130,130);

CLabellabel2=newCLabel(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();

publicstaticvoidmain(String[]args){

newGCCreation();

}

publicclassGCCreation{

publicGCCreation(){

Imageimage=newImage(display,"

Imageimage2=newImage(display,image.getImageData());

GCgc=newGC(image2);

gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));

gc.drawOval(10,10,90,40);

gc.dispose();

CLabellabel=newCLabel(shell,SWT.NULL);

label.setImage(image);

label.setBounds(10,10,130,130);

CLabellabel2=newCLabel(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();

}

publicstaticvoidmain(String[]args){

newGCCreation();

接下来请参看以下示例:

演示代码1:

viewplaincopytoclipboardprint?

importorg.eclipse.swt.events.PaintEvent;

importorg.eclipse.swt.events.PaintListener;

importorg.eclipse.swt.widgets.Canvas;

publicclassCanvasExample{

publicCanvasExample(){

Canvascanvas=newCanvas(shell,SWT.NULL);

canvas.setBounds(10,10,200,100);

canvas.addPaintListener(newPaintListener(){

publicvoidpaintControl(PaintEvente){

e.gc.drawRoundRectangle(10,10,180,80,10,10);

});

newCanvasExample();

publicclassCanvasExample{

publicCanvasExample(){

Canvascanvas=newCanvas(shell,SWT.NULL);

canvas.setBounds(10,10,200,100);

canvas.addPaintListener(newPaintListener(){

publicvoidpaintControl(PaintEvente){

e.gc.drawRoundRectangle(10,10,180,80,10,10);

});

newCanvasExample();

演示代码2:

(三角)

importorg.eclipse.swt.graphics.Region;

importorg.eclipse.swt.layout.FillLayout;

publicclassClipping{

publicClipping(){

shell.setLayout(newFillLayout());

finalCanvascanvas=newCanvas(shell,SWT.NULL);

finalImageimage=newImage(display,"

Regionregion=newRegion();

region.add(newint[]{60,10,10,100,110,100});

e.gc.setClipping(region);

e.gc.drawImage(image,0,0);

shell.setSize(200,140);

newClipping();

publicclassClipping{

publicClipping(){

shell.setLayout(newFillLayout());

finalCanvascanvas=newCanvas(shell,SWT.NULL);

finalImageimage=newImage(display,"

Regionregion=newRegion();

region.add(newint[]{60,10,10,100,110,100});

e.gc.setClipping(region);

e.gc.drawImage(image,0,0);

shell.setSize(200,140);

newClipping();

演示代码3:

(动态画布)

importorg.eclipse.swt.graphics.Point;

importorg.eclipse.swt.graphics.Rectangle;

publicclassDoubleBuffer{

publicDoubleBuffer(){

Pointsize=canvas.getSize();

intx1=(int)(Math.random()*size.x);

inty1=(int)(Math.random()*size.y);

intx2=Math.max(canvas.getBounds().width-x1-10,50);

inty2=Math.max(canvas.getBounds().height-y1-10,50);

e.gc.drawRoundRectangle(x1,y1,x2,y2,5,5);

display.timerExec(100,newRunnable(){

publicvoidrun(){

canvas.redraw();

finalCanvasdoubleBufferedCanvas=newCanvas(shell,SWT.NO_BACKGROUND);

doubleBufferedCanvas.addPaintListener(newPaintListener(){

Imageimage=(Image)doubleBufferedCanvas.getData("

double-buffer-image"

if(image==null

||image.getBounds().width!

=doubleBufferedCanvas.getSize().x

||image.getBounds().height!

=doubleBufferedCanvas.getSize().y){

image=

newImage(

display,

doubleBufferedCanvas.getSize().x,

doubleBufferedCanvas.getSize().y);

doubleBufferedCanvas.setData("

image);

GCimageGC=newGC(image);

imageGC.setBackground(e.gc.getBackground());

imageGC.setForeground(e.gc.getForeground());

imageGC.setFont(e.gc.getFont());

RectangleimageSize=image.getBounds();

imageGC.fillRectangle(0,0,imageSize.width+1,imageSize.height+1);

Pointsize=doubleBufferedCanvas.getSize();

intx2=Math.max(doubleBufferedCanvas.getBounds().width-x1-10,50);

inty2=Math.max(doubleBufferedCanvas.getBounds().height-y1-10,50);

imageGC.drawRoundRectangle(x1,y1,x2,y2,5,5);

imageGC.dispose();

doubleBufferedCanvas.redraw();

shell.setSize(300,200);

newDoubleBuffer();

publicclassDoubleBuffer{

Shellshell=newShell(dis

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 其它课程

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1