📄 snippet10.java
字号:
package org.eclipse.swt.snippets;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Snippet10 {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
//设置shell窗口标题
shell.setText("高级图形技术");
//获得系统字体数据
FontData fd = shell.getFont().getFontData()[0];
//建立字体对象
final Font font = new Font(display, fd.getName(), 20, SWT.BOLD | SWT.ITALIC);
final Image image = new Image(display, 640, 480);
final Rectangle rect = image.getBounds();
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillOval(rect.x, rect.y, rect.width, rect.height);
gc.dispose();
shell.addListener(SWT.Paint, new Listener() {
public void handleEvent(Event event) {
GC gc = event.gc;
Transform tr = new Transform(display);
tr.translate(10, 120);
tr.rotate(-30);
gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
gc.setAlpha(100);
gc.setTransform(tr);
Path path = new Path(display);
path.addString("Eclipse SWT/JFace", 0, 0, font);
gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillPath(path);
gc.drawPath(path);
tr.dispose();
path.dispose();
}
});
shell.setSize(shell.computeSize(rect.width/2 , rect.height/2 ));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
image.dispose();
font.dispose();
display.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -