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 stackoverflow.com 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.
EDIT: java.awt.Canvas seems to do what we're looking for. I'm wondering if there's a Swing equivalent.
Joined: Jun 09, 2003
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.
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)
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? )