This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adobe Illustrator Clone (somewhat)

 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 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.

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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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? )
 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Cheers
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic