<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();
}