Java by API/org.eclipse.swt.events/PaintListener
Версия от 17:43, 31 мая 2010; (обсуждение)
implements PaintListener
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
public static void main(String[] a) {
final Display d = new Display();
final Shell shell = new Shell(d);
shell.setSize(250, 200);
shell.setLayout(new FillLayout());
Canvas drawingCanvas = new Canvas(shell, SWT.NONE);
drawingCanvas.addPaintListener(new ArcExamplePaintListener());
drawingCanvas.redraw();
shell.open();
while (!shell.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
}
class ArcExamplePaintListener implements PaintListener {
public void paintControl(PaintEvent e) {
Canvas canvas = (Canvas) e.widget;
int x = canvas.getBounds().width;
int y = canvas.getBounds().height;
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLACK));
e.gc.fillArc((x - 200) / 2, (y - 200) / 2, 200, 200, 0, 90);
}
}