GC 的使用

Control, Devices, Images 1. 创建一个 或者 维持一个 GC 2. drawing 3 . 销毁 GC GC gc = new GC(display); gc.drawRectangle(...); gc.drawText(...); gc.drawImage(...); gc.dispose(); swt 使用两维 坐标系, 以(0,0)为原点, 从左到右, 从上到下递增 PaintEvent 包含了一个有效的GC instance, 而且不能销毁它 画布画图形的时候, 相对于画布的左上角图标 fillRectangle: 是一个固态控件, 没有边框 drawRectangle: 有边框 Drawing Text: 你可以显示一个text在一个单行, 也可以自动换行 改变font, size, color, style, orientation drawString() drawText() : 处理 newLine and tabs void drawText(String text, int x, int y, int flags) : Draws the specified string with its origin at the point specified by (x, y), processing newlines and expanding tabs. Uses the rules specified by flags (see Table 10-2 for more information). Table 10-2: drawText() Flags Constant Description SWT.DRAW_DELIMITER Processes newlines by drawing subsequent characters on the next line. (是否显示newLine) SWT.DRAW_TAB Processes tabs by displaying a gap between surrounding characters. (是否显示Tab) SWT.DRAW_MNEMONIC Draws an underline beneath the mnemonic character—the character preceded by an ampersand (&). Use this when drawing menus. (是否显示下划线) SWT.DRAW_TRANSPARENT Uses a transparent background when drawing the string (是否使文本透明) 如果你没有指定font, 就会使用Dispaly.getSystemFont() 你可以调用GC.setFont() ,但是要记得销毁掉 Font Font font = new Font(shell.getDisplay(), "Helvetica", 18, SWT.NORMAL); font.dispose(); // fontData 代表的只是Font 的数据, 不要销毁它 public FontData(String name, int height, int style) // 用 gc.getStringExtend() 得到String 的宽度 int strWidht = gc.getStringExtend("abc"); int strHigh = gc.getFontMetrics().getHeight(); // 绘制背景色 gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); gc.drawText("I'm in blue!"); // drawing vertical Text //setup 1. draw the text to an offscreen image FontMetrics fm = gc.getFontMetrics(); Point pt = gc.textExtent(string); Image stringImage = new Image(display, pt.x, pt.y); / / setp 2 Image(支持GIF, PNG, JPEG, TIFF,ICO,BMP,RLE) 1. 从一个file 中创建一个Image Image image= new Image(displau, "c:\\temp\\swt.png"); Image image = new Image(display, MyClass.getResourceAsStream("/temp/swt.png")); 2. 创建一个空的Image Image image1 = new Image(display, 300, 200); Image image2 = new Image(display, myRect); 3. 从 ImageData 中创建 Image Device 1. 你可以了解当前屏幕的一些属性
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
拓展运算符(spread operator)在JavaScript中用三个连续的点(...)表示。它可以在函数调用、数组字面量和对象字面量中使用,用于展开可迭代对象(如数组、字符串、Map、Set等)。 在函数调用中,拓展运算符可以将一个数组展开为独立的参数传递给函数。例如: ```javascript function add(a, b, c) { return a + b + c; } const numbers = [1, 2, 3]; console.log(add(...numbers)); // 输出:6 ``` 在数组字面量中,拓展运算符可以将一个数组中的元素展开到另一个数组中。例如: ```javascript const arr1 = [1, 2, 3]; const arr2 = [...arr1, 4, 5, 6]; console.log(arr2); // 输出:[1, 2, 3, 4, 5, 6] ``` 在对象字面量中,拓展运算符可以将一个对象的属性展开到另一个对象中。如果有相同的属性名,则后面的属性值会覆盖前面的。例如: ```javascript const obj1 = { a: 1, b: 2 }; const obj2 = { ...obj1, c: 3 }; console.log(obj2); // 输出:{ a: 1, b: 2, c: 3 } ``` 拓展运算符还可以用于克隆数组和对象,因为它创建了一个数组或对象副本。例如: ```javascript const originalArray = [1, 2, 3]; const newArray = [...originalArray]; console.log(newArray); // 输出:[1, 2, 3] const originalObject = { a: 1, b: 2 }; const newObject = { ...originalObject }; console.log(newObject); // 输出:{ a: 1, b: 2 } ``` 拓展运算符的应用还有很多,它可以简化代码并提高可读性。希望这个解答对你有帮助!如果你还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值