No issues for this version


Welcome to the jdrawinglib wiki!

jdrawinglib is a small library that will help you draw on a canvas with some basic OOP. In here you'll find some basic documentation that will (hopefully) help you get started.

Getting started

  1. Get a copy of jdrawinglib:
    1. You can either build it from source with the instructions found in here.
    2. Or download a compiled version.
  2. Browse the examples and test them (there are some included in the library).
  3. Try some sample applications.


View contact details...

More data



No issues for this version


Here are some coding examples of jdrawinglib.
Basically we have a Canvas, and a lot of geometric elements. The canvas itself is a JPanel, so you can use it however you see fit, but for beginners sake we also have a CanvasFrame which is the one that we'll use in the examples.

Usage Template

The basic template to create a CanvasFrame and setting everything up is as follows:


public class Template {
    public static void main(String[] args) {
        //The name that appears in the window
        String title = "Template";
        //We need to create a new frame
        CanvasFrame frame = new CanvasFrame(title);
        //And make it visible
        //Set a size in pixels (whichever you want)
        frame.setSize(550/*width*/, 550/*height*/);
        //Extract a reference to the canvas from the frame
        Canvas canvas = frame.getCanvas();
        //Tell the canvas to center the origin of coordinates,  
        //which by default is located in the upper left corner
        //Tell the canvas to invert the Y axis, this way we will
        //consider all positive Y increments from the origin of
        //coordinates to the title bar

        // -->         Application logic goes HERE            <--

        //In order for the elements to be drawn in the canvas, is
        //necessary to call 'canvas.repaint()' after we add the
        //elements to it.
        //PS: There's an autorepaint feature (disabled by default).

The basic application logic is pretty simple, you create a new graphical element, modify its attributes and add it to the canvas.

Basic graphical elements

There are three basic graphical elements all of which inherit from GraphicE:

  • GraphicE: The most basic elements, which are primarily defined by:
    • a color (more precisely a Paint)
    • a stroke, used to draw the element
    • and the possibility to be moved on the (x,y) plane
  • GFillableE: This extend a bit GraphicE by adding:
    • a fill paint which will be the one used to fill the element
    • and a fill flag which if false (default) will make GFillableE act as GraphicE regardless of the fill paint.
  • Graphic: This are containers for GraphicE objects, and allow the creation of complex graphics using affine transforms, clipping areas, etc.

All of this elements are contained in the package

Basic element list

  • GArc: An arc of an oval
  • GCircle: A circle (an oval contained on a square box)
  • GImage: An image, this object can also be used as Paint
  • GLine: Represents a line segment
  • GOval: An oval contained in a box
  • GPath: Represents an ordered array of pixels printed joining the points in order
  • GPoint: Represents a pixel in the screen, although it can be drawn as a cross.
  • GPointArray: Represents an unordered array of pixels.
  • GPoly: A closed GPath
  • GRegPoly: A regular polygon with a given number of sides inscribed in a circle
  • GRectangle: A rectangle,
  • GString: Represents a String on the canvas
  • GVector: A line segment with a small arrow on one end
  • Graphic: GraphicE container

Graphical elements extras

There are some extra classes in this library, some of them are pretty handy, and the others... not so much. The idea behind this classes was to show what can be done with a few graphical objects, but time passed, and some of them are pretty neat.
All of this elements are contained in the package.

Three basic categories can be found in the extras package:

  • Extensions of the Graphic class:
    • GAxis: Draws a set of Cartesian axes, with the possibility of having a grid.
    • GGrid: Draws a grid on the canvas.
    • GPVector: Represents a vector and it's projections.
    • GVectorPolygon: Represents a vectorial polygon.
    • GPixMap: Represents a pixmap (an image expressed pixel by pixel).
    • GSprite: An array of GPixMap used to create animations.
  • Additional components for the Graphic class:
    • GClip: Wraps a clipping zone.
    • GTransform: Wraps an affine transform.
  • Formula related classes:
    • GFormula: Solves an equation (GCalculable) for a given interval.
    • GCalculable: Wraps a formula in code.
    • GCalculableTimer: Solves an equation using multiple threads, this may sound silly, but check out ParametricFun.

Other examples

Go to top