Java Qt Extensions

Examples

Example6 - Graphics

A demonstration of graphical capabilities.

For graphics operations QSwing uses an API similar to Java2D API.

Code

package yu.ac.bg.etf.javaqx.examples;

import yu.ac.bg.etf.javaqx.qswing.JQComponent;
import yu.ac.bg.etf.javaqx.qswing.QSwing;
import yu.ac.bg.etf.javaqx.qswing.events.QSwingEvent;
import yu.ac.bg.etf.javaqx.qswing.graphics.BasicStroke;
import yu.ac.bg.etf.javaqx.qswing.graphics.Color;
import yu.ac.bg.etf.javaqx.qswing.graphics.CubicCurve;
import yu.ac.bg.etf.javaqx.qswing.graphics.Ellipse;
import yu.ac.bg.etf.javaqx.qswing.graphics.GradientPaint;
import yu.ac.bg.etf.javaqx.qswing.graphics.Graphics;
import yu.ac.bg.etf.javaqx.qswing.graphics.Line;
import yu.ac.bg.etf.javaqx.qswing.graphics.Rectangle;
import yu.ac.bg.etf.javaqx.qswing.graphics.RoundRectangle;
import yu.ac.bg.etf.javaqx.qswing.graphics.Stroke;
import yu.ac.bg.etf.javaqx.qswing.graphics.TexturePaint;

/**
 * Graphics Example.
 */
public class Example6Graphics extends JQComponent {

  private final GradientPaint gradientPaint;
  private final TexturePaint texturePaint;
  private final BasicStroke basicStroke;

  /**
   * Constructs new Example6Graphics object.
   */
  public Example6Graphics() {
    setName("Graphics");
    setFixedSize(500420);
    enableEvents(QSwingEvent.PAINT_EVENT_MASK);
    basicStroke = new BasicStroke(2, BasicStroke.CAP_SQUARE,
                                  BasicStroke.JOIN_MITER, 10.0f,
                                  new float[] {2f4f});
    gradientPaint = new GradientPaint(100180, Color.DARK_RED, 180240,
                                      Color.DARK_GREEN, true);
    texturePaint = new TexturePaint(QSwing.crateImage(
                        Example6Graphics.class.getResource("GreenTeaCup.png")));
  }

  protected void paintComponent(Graphics g) {
    g.draw(new Line(20808020));
    g.draw(new Rectangle(100208060));
    g.draw(new Ellipse(200208060));
    g.draw(new RoundRectangle(3002080602020));
    g.draw(new CubicCurve(40020440204008048080));
    Stroke s = g.getStroke();
    g.setStroke(basicStroke);
    g.draw(new Line(2016080100));
    g.draw(new Rectangle(1001008060));
    g.draw(new Ellipse(2001008060));
    g.draw(new RoundRectangle(30010080602020));
    g.draw(new CubicCurve(400100440100400160480160));
    g.setColor(Color.DARK_BLUE);
    g.setStroke(s);
    g.draw(new Line(2024080180));
    g.fill(new Rectangle(1001808060));
    g.draw(new Rectangle(1001808060));
    g.fill(new Ellipse(2001808060));
    g.draw(new Ellipse(2001808060));
    g.fill(new RoundRectangle(30018080602020));
    g.draw(new RoundRectangle(30018080602020));
    g.fill(new CubicCurve(400180440180400240480240));
    g.draw(new CubicCurve(400180440180400240480240));
    g.setPaint(gradientPaint);
    g.draw(new Line(2032080260));
    g.fill(new Rectangle(1002608060));
    g.draw(new Rectangle(1002608060));
    g.fill(new Ellipse(2002608060));
    g.draw(new Ellipse(2002608060));
    g.fill(new RoundRectangle(30026080602020));
    g.draw(new RoundRectangle(30026080602020));
    g.fill(new CubicCurve(400260440260400320480320));
    g.draw(new CubicCurve(400260440260400320480320));
    g.setPaint(texturePaint);
    g.draw(new Line(2040080340));
    g.fill(new Rectangle(1003408060));
    g.draw(new Rectangle(1003408060));
    g.fill(new Ellipse(2003408060));
    g.draw(new Ellipse(2003408060));
    g.fill(new RoundRectangle(30034080602020));
    g.draw(new RoundRectangle(30034080602020));
    g.fill(new CubicCurve(400340440340400400480400));
    g.draw(new CubicCurve(400340440340400400480400));
  }

  public static void main(String[] args) {
    Example6Graphics graphicsExample = new Example6Graphics();
    graphicsExample.setVisible(true);
    QSwing.startEventLoop(true);
  }

}

Screenshots

Graphics on
Windows Vista
Graphics on
Windows XP
Graphics on
Windows 98
Graphics on
SUSE Linux
Graphics on
Ubuntu Linux