gcdemo2.java
来自「java图形界面开发」· Java 代码 · 共 50 行
JAVA
50 行
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.*;
public class GCDemo2 {
public static Display myDisplay;
public static boolean internalCall = false;
public static void main(String[] args) {
internalCall = true;
myDisplay = new Display();
GCDemo2 gcd = new GCDemo2();
gcd.runDemo(myDisplay);
}
public void runDemo(Display display) {
myDisplay = display;
Shell shell = new Shell(display);
shell.setSize(200, 240);
shell.setText("GC Demo2");
Canvas canvas = new Canvas(shell, SWT.BORDER);
canvas.setSize(150, 150);
canvas.setLocation(20, 20);
//add a paintlistener so that repaint events
//will redraw the rectangle when necessary
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.drawRectangle(3, 5, 20, 25);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
if (internalCall) display.dispose();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?