Java Tutorial/SWT 2D Graphics/GC — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 15:18, 31 мая 2010

Avoid creating a GC

You can avoid creating a GC and just use the one from the event. In this case, you shouldn"t dispose that GC.



shell.addPaintListener(new PaintListener() {
  public void paintControl(PaintEvent event) {
    event.gc.drawRectangle();
  }
});





Graphics

  1. The GC class (short for graphical context) forms the core of SWT"s graphics engine.
  2. GC offers all the methods required for drawing shapes, text, and images.
  3. You can draw on Controls, Devices, or other Images.

Generally, drawing lifecycles consists of the following:

  1. Creating or obtaining a GC to draw on the desired target
  2. Drawing
  3. If you created the GC, disposing the GC

In code, the drawing lifecycle looks like this:



GC gc = new GC(display);
gc.drawRectangle(...);
gc.drawText(...);
gc.drawImage(...);
gc.dispose();