PA <Pa***@hotmail.com> wrote in message news:<Ne********************@newsb.telia.net>...
Hi,
I want to implement the following in an applet:
^
|
| + + + + + +H
| +
| +
| H
| +
| +
| +
| H+++++++H
|
|
|-------------------------------------->
Given this chart the user can change the shape of the curve
by dragging the handles H up/down or left/right.
Try java.awt.geom.Shape
Say you're drawing on p, an instance of some subclass of JComponent
that you're writing. Then p.getGraphics() returns g, a Graphics
object. But g is actually of class java.awt.Graphics2D, and you can
cast it to that class. Then override the paintComponent method in p's
class to use draw(Shape).
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.draw(myShape1);
g2.draw(myShape2);
// etc.
}
One Shape that gives straight lines is java.awt.geom.Line2D.Float.
If the thing on the right is a parabolic or elliptical segment with an
H in the middle, then try java.awt.geom.Quad2D.Float. Quad2D has a
"control point" which is related to the midpoint of the arc, though it
hovers a certain distance away from that midpoint.