Search code examples
javaawtgraphics2d

How to create a Graphics2D instance?


What's the easiest way in Java SE 7 to obtain an instance just to plot a few points for debugging? Desktop environment.


Solution

  • You could use a BufferedImage:

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = image.createGraphics();