01: import java.awt.Graphics2D;
02: import java.awt.geom.Ellipse2D;
03: 
04: /**
05:    A point with a label showing the point's coordinates.
06: */
07: public class LabeledPoint
08: {
09:    /**
10:       Construct a labeled point.
11:       @param anX the x coordinate
12:       @param aY the y coordinate
13:    */
14:    public LabeledPoint(double anX, double aY)
15:    {
16:       x = anX;
17:       y = aY;
18:    }
19: 
20:    /**
21:       Draws the point as a small circle with a coordinate label.
22:       @param g2 the graphics context
23:    */
24:    public void draw(Graphics2D g2)
25:    {
26:       // Draw a small circle centered around (x, y)
27: 
28:       Ellipse2D.Double circle = new Ellipse2D.Double(
29:             x - SMALL_CIRCLE_RADIUS,
30:             y - SMALL_CIRCLE_RADIUS,
31:             2 * SMALL_CIRCLE_RADIUS,
32:             2 * SMALL_CIRCLE_RADIUS);
33: 
34:       g2.draw(circle);
35:     
36:       // Draw the label
37: 
38:       String label = "(" + x + "," + y + ")";
39: 
40:       g2.drawString(label, (float) x, (float) y);
41:    }
42: 
43:    private static final double SMALL_CIRCLE_RADIUS = 2;
44: 
45:    private double x;
46:    private double y;
47: }