Hi
Im a beginner with Java. In few words, I need to build a GUI with 2D
graphics. The user must create one or more rectangules just inserting 4
points for each figure. Aften then, info about these figures should be
written in a XML file. Can someone suggest me something useful to do
this (hints, tools, urls, documents, guides etc)?
thanks
GG
Roland - 22 Jan 2005 09:46 GMT
> Hi
> Im a beginner with Java. In few words, I need to build a GUI with 2D
[quoted text clipped - 6 lines]
>
> GG
Java tutorial:
<http://java.sun.com/docs/books/tutorial/>
In particlar the 2D trail:
<http://java.sun.com/docs/books/tutorial/2d/index.html>
The Java 2D guide:
<http://java.sun.com/j2se/1.5.0/docs/guide/2d/index.html>

Signature
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
Fahd Shariff - 23 Jan 2005 00:27 GMT
I wrote something similar to this. Well, simply put all you need to do
is listen for mouse clicks on the panel and connect them using Graphics
methods after the fourth click. Then repaint the panel.
(But obviously the four clicks might not form a rectangle. They might
form any old polygon. If you strictly want a rectangle you might have
to check the validity of the points.)
You will need to have a data model to store everything. So you need a
rectangle class and a Collection in which you can add/remove
rectangles. After the fourth click, create a rectangle object and
store it in the collection. Then when you want to save the diagram you
can loop through the collection and generate the appropriate XML for
each rectangle.
Your XML for a diagram with rectangles might look like:
<diagram>
<rectangle x="10" y="10" width="100" height="50" />
<rectangle x="10" y="100" width="50" height="100" />
</diagram>
Hope this helps,
--
Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking... "
Andrew Thompson - 23 Jan 2005 01:33 GMT
> (But obviously the four clicks might not form a rectangle. They might
> form any old polygon. If you strictly want a rectangle you might have
> to check the validity of the points.)
A common strategy is to lock down either the X, or Y as needed.
If you offer 'resize' bars afterwards, it is very easy and
intuitive for the end user. They simply 'click' the box
approximately where it is used, then resize/drag to need.

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane