import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import java.io.*; import java.awt.*; import java.awt.event.*; import org.w3c.dom.*; public class XMLJoonis extends Frame implements ActionListener, MouseListener, MouseMotionListener{ Button nupp = new Button("Lae"); Button salvesta=new Button("Salvesta"); Button tryki=new Button("Trüki"); Button kustuta=new Button("Kustuta"); String failinimi="joonistusandmed.xml"; Document d; Node juur, joon; public XMLJoonis(){ setLayout(new FlowLayout()); add(nupp); add(salvesta); add(tryki); add(kustuta); nupp.addActionListener(this); salvesta.addActionListener(this); tryki.addActionListener(this); kustuta.addActionListener(this); addMouseListener(this); addMouseMotionListener(this); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent evt){ System.exit(0); } }); alusta(); setSize(400,300); setVisible(true); } public void actionPerformed(ActionEvent e){ if(e.getSource()==nupp){ try{ d=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(failinimi); juur=(Element)d.getFirstChild(); repaint(); } catch(Exception viga){System.out.println("Probleem lugemisel: "+viga); } } if(e.getSource()==salvesta){ try{ Transformer t=TransformerFactory.newInstance().newTransformer(); FileOutputStream valja=new FileOutputStream(failinimi); t.transform(new DOMSource(d), new StreamResult(valja)); valja.close(); } catch(Exception viga){ viga.printStackTrace(); } } if(e.getSource()==tryki){System.out.println(d.getFirstChild());} if(e.getSource()==kustuta){alusta();} } public void paint(Graphics g){ NodeList jooned=d.getFirstChild().getChildNodes(); for(int i=0; i