swt绘图练习

20 篇文章 0 订阅
<pre name="code" class="java">	public static void main(String[] args) {
		final Display display = Display.getDefault();
		final Shell shell = new Shell(display);
		shell.setSize(200, 200);
		shell.addPaintListener(new PaintListener() {
			
			public void paintControl(PaintEvent e) {
				GC gc = e.gc;
				Rectangle clientArea = shell.getClientArea();
				int width = clientArea.width;
				int height = clientArea.height;
//				gc.setClipping(20, 20, width-40, height-40);//剪切
//				gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));//设置背景色
//				gc.fillPolygon(new int[]{10,10,width,0,width/2,height});//填充多边形
//				gc.drawRectangle(10, 10, width-20, height-20);//绘制长方形
//				gc.drawRoundRectangle(5,5,90,45,25,15);//绘制圆角长方形
//				gc.drawOval(0, 0, width, height);//绘制圆形
//				gc.setLineStyle(SWT.LINE_DASHDOTDOT);//设置线的风格
//				gc.setLineWidth(3);//设置线的宽度
//				gc.drawArc(0, 0, width, height, 90, 200);//设置圆弧线
//				gc.drawText("hello", 5, 5);//绘制文本,识别制表符和换行符
//				Font font = new Font(display, "Arial", 20, 20);
//				gc.setFont(font);//设置字体
//				gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));//设置前景色
//				gc.drawText("hello\tthere\nwide\tworld", 5, 25);//绘制文本,识别制表符和换行符
//				gc.drawString("hello\tthere\nwide\tworld", 5, 25);//绘制文本,不识别制表符和换行符
//				font.dispose();
				//图形填充
//				gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); 
//				gc.fillPolygon(new int[] { 25,5,45,45,5,45 });//填充三角形
//				gc.fillRectangle(5,5,90,45);//填充矩形
//				gc.fillRoundRectangle(5,5,90,45,25,15);//填充圆角长方形
//				gc.fillOval(0, 0, width, height);//填充圆形
//				gc.fillArc(0, 0, width, height, 90, 200);//填充圆弧线
//				gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); 
//				gc.setForeground(display.getSystemColor(SWT.COLOR_CYAN)); 
//				gc.fillGradientRectangle(5,5,90,45,true);//渐变色填充矩形
				
				//XOR异或处理
//				gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); 
//				gc.fillRectangle(5,5,90,45); 
//				gc.setXORMode(true); 
//				gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); 
//				gc.fillRectangle(20,20,50,50); 
//				gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); 
//				gc.fillOval(80,20,50,50);
				
				Image image = new Image(display, "c:/xiaomi.PNG");
				Rectangle bounds = image.getBounds();
				gc.drawImage(image, bounds.x, bounds.y);//绘制图片
				
			}
		});
		
		shell.open();
		while(!shell.isDisposed())
		{
			if(!display.readAndDispatch())
			{
				display.sleep();
			}
		}
		display.dispose();
	}


 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值