画布图形实例.docx
《画布图形实例.docx》由会员分享,可在线阅读,更多相关《画布图形实例.docx(29页珍藏版)》请在冰豆网上搜索。
![画布图形实例.docx](https://file1.bdocx.com/fileroot1/2023-2/2/3ba3b07b-afd6-4f72-8888-a88b55fd80f7/3ba3b07b-afd6-4f72-8888-a88b55fd80f71.gif)
画布图形实例
package;
import
import
import
import
import
import
publicclassGCCreation{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicGCCreation(){
Imageimage=newImage(display,"C:
/icons/");
Imageimage2=newImage(display,());
GCgc=newGC(image2);
);
(10,10,90,40);
();
CLabellabel=newCLabel(shell,;
(image);
(10,10,130,130);
CLabellabel2=newCLabel(shell,;
(image2);
(150,10,130,130);
();
();
while(!
()){
if(!
()){
();
}
}
();
}
publicstaticvoidmain(String[]args){
newGCCreation();
}
}
package;
importclassGCCreation{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicGCCreation(){
Imageimage=newImage(display,"C:
/icons/");
Imageimage2=newImage(display,());
GCgc=newGC(image2);
);
(10,10,90,40);
();
CLabellabel=newCLabel(shell,;
(image);
(10,10,130,130);
CLabellabel2=newCLabel(shell,;
(image2);
(150,10,130,130);
();
();
while(!
()){
if(!
()){
();
}
}
();
}
publicstaticvoidmain(String[]args){newGCCreation();
}
}
接下来请参看以下示例:
演示代码1:
viewplaincopytoclipboardprintpackage;
importimport
import
import
import
import
publicclassCanvasExample{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicCanvasExample(){
Canvascanvas=newCanvas(shell,;
(10,10,200,100);
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
10,180,80,10,10);
}
});
();
();
while(!
()){
if(!
()){
();
}
}
();
}
}
package;
importclassCanvasExample{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicCanvasExample(){
Canvascanvas=newCanvas(shell,;
(10,10,200,100);
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
10,180,80,10,10);
}
});
();
();
while(!
()){
if(!
()){
();
}
}
();
}
}
演示代码2:
(三角)
viewplaincopytoclipboardprint
package;
import
import
import
import
import
import
import
import
import
publicclassClipping{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicClipping(){
(newFillLayout());
finalCanvascanvas=newCanvas(shell,;
finalImageimage=newImage(display,"C:
/icons/");
(newPaintListener(){
Regionregion=newRegion();(newint[]{60,10,10,100,110,100});
0,0);
}
});
(200,140);
();
while(!
()){
if(!
()){
();
}
}
();
}
publicstaticvoidmain(String[]args){newClipping();
}
}
package;
importclassClipping{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicClipping(){
finalCanvascanvas=newCanvas(shell,;
finalImageimage=newImage(display,"C:
/icons/");
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
Regionregion=newRegion();
(newint[]{60,10,10,100,110,100});
0,0);
}
});
(200,140);
();
while(!
()){
if(!
()){
();
}
}
();
}
publicstaticvoidmain(String[]args){
newClipping();
}
}
演示代码3:
(动态画布)
viewplaincopytoclipboardprint
package;
import
import
import
import
import
import
import
import
import
import
import
publicclassDoubleBuffer{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicDoubleBuffer(){
(newFillLayout());
finalCanvascanvas=newCanvas(shell,;
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
Pointsize=();
intx1=(int)()*;
inty1=(int)()*
intx2=().width-x1-10,50);inty2=().height-y1-10,50);
y1,x2,y2,5,5);
(100,newRunnable(){
publicvoidrun(){
();
}
});
}
});
finalCanvasdoubleBufferedCanvas=newCanvas(shell,;
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
Imageimage=(Image)("double-buffer-image");
if(image==null
||().width!
=().x
||().height!
=().y){
image=
newImage(
display,
().x,
().y);
("double-buffer-image",image);
}
GCimageGC=newGC(image);
RectangleimageSize=();
(0,0,+1,+1);
Pointsize=();
intx1=(int)()*;
inty1=(int)()*;
intx2=().width-x1-10,50);
inty2=().height-y1-10,50);
(x1,y1,x2,y2,5,5);
0,0);
();
(100,newRunnable(){
publicvoidrun(){
();
}
});
}
});
(300,200);
();
while(!
()){
if(!
()){
();
();
publicstaticvoidmain(String[]args){newDoubleBuffer();
}
}
package;
importclassDoubleBuffer{
Displaydisplay=newDisplay();Shellshell=newShell(display);publicDoubleBuffer(){
(newFillLayout());
finalCanvascanvas=newCanvas(shell,;
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
Pointsize=();
intx1=(int)()*;
inty1=(int)()*;
intx2=().width-x1-10,50);
inty2=().height-y1-10,50);
y1,x2,y2,5,5);
(100,newRunnable(){
publicvoidrun(){
();
});
}
});
finalCanvasdoubleBufferedCanvas=newCanvas(shell,;
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
Imageimage=(Image)("double-buffer-image");
if(image==null
||().width!
=().x
||().height!
=().y){
image=
newImage(
display,
().x,
().y);
("double-buffer-image",image);
}
GCimageGC=newGC(image);
Rectangle
imageSize=();
(0,0,+1,+1);
Pointsize=();
intx1=(int)()*;
inty1=(int)()*;
intx2=().width-x1-10,50);
inty2=().height-y1-10,50);
(x1,y1,x2,y2,5,5);
0,0);
();
(100,newRunnable(){publicvoidrun(){
();
}
});
}
});
(300,200);
();
while(!
()){
if(!
()){
();
}
}
();
}
publicstaticvoidmain(String[]args){
newDoubleBuffer();
}
}
演示代码4:
(图片)
viewplaincopytoclipboardprint
package;
import
import
import
import
import
import
import
import
import
import
import
import
publicclassDrawImages{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicDrawImages(){
(newFillLayout());
Canvascanvas=newCanvas(shell,;
finalImageimage=newImage(display,"C:
/icons/");
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
10,10);
0,0,100,100,200,10,200,50);
});
(430,200);
();
captureControl(canvas,"");
while(!
()){
if(!
()){
();
}
}
();
}
publicstaticvoidcaptureControl(Controlcontrol,Stringfile){
GCgc=newGC(control);
Imageimage=newImage(),().x,().y);
(image,0,0);
ImageLoaderloader=newImageLoader();
=newImageData[]{()};
(file,;
();
}
publicstaticvoidmain(String[]args){
newDrawImages();
}
}
package;
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicDrawImages(){
(newFillLayout());
Canvascanvas=newCanvas(shell,;
finalImageimage=newImage(display,"C:
/icons/");
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
10,10);
0,0,100,100,200,10,200,50);
}
});
(430,200);
();
captureControl(canvas,"");
while(!
()){
if(!
()){
();
}
}
();
}
publicstaticvoidcaptureControl(Controlcontrol,Stringfile){
GCgc=newGC(control);
Imageimage=newImage(),().x,().y);
(image,0,0);
ImageLoaderloader=newImageLoader();=newImageData[]{()};
(file,;
();
}
publicstaticvoidmain(String[]args){
newDrawImages();
}
}
演示代码5:
(画线)
viewplaincopytoclipboardprintpackage;
import
import
import
import
import
import
import
publicclassDrawings{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicDrawings(){
(newFillLayout());
Canvascanvas=newCanvas(shell,;
);
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
"(default)",10,10);
"",10,30);
"",10,50);
"",10,70);
"",10,90);
"Linewidth=1(default)",10,120);
"Linewidth=3",10,140);
intstart=150;
15,start+200,15);
35,start+200,35);
55,start+200,55);
75,start+200,75);
95,start+200,95);
125,start+200,125);
145,start+200,145);
int[]points=newint[3*2];
points[0]=10;
points[1]=10;
points[2]=10;
points[3]=100;
points[4]=100;
points[5]=100;
10,200,100,0,-90);
60,220,60);
0,110,120);
}
});
();
();
while(!
()){
if(!
()){
();
}
();
}
publicstaticvoidmain(String[]args){
newDrawings();
}
}
package;
importclassDrawings{
Displaydisplay=newDisplay();
Shellshell=newShell(display);publicDrawings(){
(newFillLayout());
Canvascanvas=newCanvas(shell,;
);
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
"(default)",10,10);
"",10,30);
"",10,50);
"",10,70);
"",10,90);
"Linewidth=1(default)",10,120);
"Linewidth=3",10,140);
intstart=
150;
15,start+200,15);
35,start+200,35);
55,start+200,55);
75,start+200,75);
95,start+200,95);
125,start+200,125);
145,start+200,145);
int[]points
=newint[3*2];
points[0]=
10;
points[1]=
10;
points[2]=
10;
points[3]=
100;
points[4]=
100;
points[5]=
100;
10,200,100,0,-90);
60,220,60);
0,110,120);
}
});
();
while(!
()){
if(!
()){
();
}
}
();
}
publicstaticvoidmain(String[]args){newDrawings();
}
}
演示代码6:
(文本效果)viewplaincopytoclipboardprintpackage;
import
import
import
import
import
import
import
import
import
importimport
publicclassDrawText{
Displaydisplay=newDisplay();
Shellshell=newShell(display);
publicDrawText(){
(newFillLayout());
finalCanvascanvas=newCanvas(shell,;
finalImageimage=newImage(display,"C:
/icons/");
(newPaintListener(){
publicvoidpaintControl(PaintEvente){
Rectanglesize=();
0,0,,,0,0,().x,().y);
Fontfont=newFont(display,"Tahoma",18,;
Stringenglish="SWTrocks!
";
Stringchinese="\u4e2d\u6587\u6c49\u5b57\u6d4b\u8bd5";
10,10);
10,80,true);
Stringtext="Texttobedrawninthecenter";
PointtextSize=().x-/2,().y-/2);
});
(300,150);
();
while(!
()){
if(!
()){
()