import java.awt.*;
import java.awt.event.*;

import javax.xml.parsers.*; 
import org.w3c.dom.*; 

public class ch11_07 
{
    static int numberFigures = 0;
    static  int x[] = new int[100];
    static int y[] = new int[100];
    static int radius[] = new int[100];

    public static void displayDocument(String uri) 
    {
        try {

        DocumentBuilderFactory dbf =
            DocumentBuilderFactory.newInstance();

        DocumentBuilder db = null;
        try {
            db = dbf.newDocumentBuilder();
        } 
        catch (ParserConfigurationException pce) {}

        Document document = null;
            document = db.parse(uri);

            display(document);

        } catch (Exception e) {
            e.printStackTrace(System.err);
        }

    } 

    public static void display(Node node) 
    {
        if (node == null) {
            return;
        }

        int type = node.getNodeType();

        if (node.getNodeType() == Node.DOCUMENT_NODE) {
            display(((Document)node).getDocumentElement());
        }

        if (node.getNodeType() == Node.ELEMENT_NODE) {

            if (node.getNodeName().equals("CIRCLE")) {

                NamedNodeMap attrs = node.getAttributes();

                x[numberFigures] = Integer.parseInt((String)attrs.getNamedItem("X").getNodeValue());

                y[numberFigures] = Integer.parseInt((String)attrs.getNamedItem("Y").getNodeValue());

                radius[numberFigures] = Integer.parseInt((String)attrs.getNamedItem("RADIUS").getNodeValue());

                numberFigures++;
            }

            NodeList childNodes = node.getChildNodes();

            if (childNodes != null) {
                int length = childNodes.getLength();
                for (int loopIndex = 0; loopIndex < length; loopIndex++) {
                    display(childNodes.item(loopIndex));
                }
            }
        }
    } 

    public static void main(String args[]) 
    {
        displayDocument(args[0]);

        AppFrame f = new AppFrame(numberFigures, x, y, radius);

        f.setSize(400, 400);

        f.addWindowListener(new WindowAdapter() {public void
            windowClosing(WindowEvent e) {System.exit(0);}});

        f.show();
    } 
}

class AppFrame extends Frame
{
    int numberFigures;
    int[] xValues;
    int[] yValues;
    int[] radiusValues;

    public AppFrame(int number, int[] x, int[] y, int[] radius)
    {
        numberFigures = number;
        xValues = x;
        yValues = y;
        radiusValues = radius;
    }

    public void paint(Graphics g)
    {
        for(int loopIndex = 0; loopIndex < numberFigures; loopIndex++){
            g.drawOval(xValues[loopIndex], yValues[loopIndex], radiusValues[loopIndex], radiusValues[loopIndex]);
        }
    }
}