File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Adobe Illustrator Clone (somewhat) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adobe Illustrator Clone (somewhat)" Watch "Adobe Illustrator Clone (somewhat)" New topic

Adobe Illustrator Clone (somewhat)

Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

Hello everyone,

I am a student who has to implement a vector graphics editor as a coursework. We have decided to use Java because the Swing framework is simple to use and a naturally Java is cross-platform. Our program will be fairly simple. It will only handle: lines, polygones (unfilled) and curves

Although we have found all the tools we need and how to use them here, there's one thing that's missing: The Canvas

I have found a thread on that will allow use to implement this by overriding protected paintComponent(Graphics g) if it's absolutely necessary.

However since there's much to do I want to save as much time as possible. I was wondering if you guys know any 3rd-party open classes/package that would allow us to scribble some basic polygones, lines and curves. It probably exists but I'm getting very unlucky with Google

Alternatively, if you have any other sources / tips on how to properly implement a canvas that could help too.

Many thanks

EDIT: java.awt.Canvas seems to do what we're looking for. I'm wondering if there's a Swing equivalent.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
the stackoverflow link also has a link to swing's 'Performing Custom Painting'.
I'd say reading that lesson/tutorial would be your best option.
Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

Hello Micheal.

Thanks for your reply. I think you're right, implementing our own JPanel is probably the best solution.

This tutorial is good but it's too basic. We need something that with more functionality such as the java.awt.Graphics2D. I have found some tutorials on this but I'm wondering what are consequences of using the more advanced Graphics2D class as oppose to the Graphics. This it slower? Less stable?

Also I'm a little bit confused because I've noticed that both the Graphics and Graphics2D classes are part of the AWT package. However, we need to use Swing and I've been told we should mix AWT and Swing. Why is that? If we can do exactly the same thing in AWT we might want to stick to that because it's faster.
(that last question is maybe a little bit off-topic, sorry about that)
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

In 99.999% of the cases, the Graphics object you get for painting is a Graphics2D object. Graphics is the super class of Graphics2D, and technically it could in the future get a Graphics3D sub class for, you've guessed it, 3D painting. (And who knows, Graphics4D for painting in time? )

How To Ask Questions How To Answer Questions
Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

Hmm... I see. I think I did hear something about how Graphics2D came as an update of Graphics (in Java 1.2 or so I believe).

Anyway, thanks for your help guys I've already got a bit of code working, I'll manage from here on.

Darryl Burke

Joined: May 03, 2008
Posts: 5115

Rob Spoor wrote:In 99.999% of the cases, the Graphics object you get for painting is a Graphics2D object.

100%. The page was lost forever when Oracle took over Sun, but it had been announced quite a long time ago that all Graphics references would be instances of Graphics2D.

luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
subject: Adobe Illustrator Clone (somewhat)
It's not a secret anymore!