import javax.swing.JFrame;
import java.awt.BorderLayout;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import org.w3c.dom.NodeList;
import java.io.File;

public class JBookOrder extends JFrame {
   public JBookOrder() {
     super("JBookOrder");
     getContentPane().setLayout(new BorderLayout());  
   }
   public void addJCustomer(String nombre,String rfc,String nTarjeta){
     JCustomer customer = 
     new JCustomer(  nombre, rfc, nTarjeta);
     getContentPane().add(customer,"Center"); 
   }
   public void addJReceipt(String subTotal,String tax,String total){
     JReceipt receipt = new JReceipt( subTotal, tax, total);
     getContentPane().add(receipt,"South" ); 
   }
   public void cargarXML(String archivo){
     try {
     String nombre,rfc,numTarjeta;
     DocumentBuilderFactory dbf = 
        DocumentBuilderFactory.newInstance();     
     DocumentBuilder db = dbf.newDocumentBuilder();
     Document _doc=db.parse(new File(archivo));
     Element eCustomer = (Element)
       _doc.getElementsByTagName("Customer").item(0);
     if (eCustomer != null) {
         rfc="";
         if (eCustomer.hasAttribute("rfc")) {
           rfc= eCustomer.getAttribute("rfc");
         }
         Element eName = (Element)
           eCustomer.getElementsByTagName("Name").item(0);
         Element eCardNum = (Element)
           eCustomer.getElementsByTagName("Cardnum").item(0);
         Text dato=(Text) eName.getFirstChild();
         nombre=dato.getData();
         dato=(Text) eCardNum.getFirstChild();
         numTarjeta=dato.getData();
         this.addJCustomer(nombre,rfc,numTarjeta);
     }
     
    } catch (Exception ex) {
       ex.printStackTrace();
    }     
   }
   public static void main(String [] args) {
      JBookOrder jbook = new JBookOrder();
      jbook.cargarXML(args[0]);
      jbook.addJReceipt("$53.75","$4.43","$58.18");
      jbook.pack();
      jbook.show();
   }

}