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