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 XMLJoonis2 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"; Choice kujundivalik=new Choice(); Color[] varvid={Color.pink, Color.black, Color.yellow}; String[] varvinimed={"Lilla", "Must", "Kollane"}; Choice varvivalik=new Choice(); Document d; Node juur, kujund; public XMLJoonis2(){ setLayout(new FlowLayout()); add(nupp); add(salvesta); add(tryki); add(kustuta); add(kujundivalik); add(varvivalik); 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); } }); kujundivalik.add("Joon"); kujundivalik.add("Ristkülik"); for(int i=0; ix2){ int abi=x1; x1=x2; x2=abi; } if(y1>y2){ int abi=y1; y1=y2; y2=abi; } // g.drawRect(x1, y1, x2-x1, y2-y1); if(e.getX() >x1 && e.getX() < x2 && e.getY() > ) } } public void mousePressed(MouseEvent e) { if(kujundivalik.getSelectedIndex()==0){ kujund=d.createElement("joon"); } if(kujundivalik.getSelectedIndex()==1){ kujund=d.createElement("ristkylik"); } juur.appendChild(kujund); lisaVarv(); lisaPunkt(e.getX(), e.getY()); } public void mouseDragged(MouseEvent e){ if(kujundivalik.getSelectedIndex()==0){ lisaPunkt(e.getX(), e.getY()); } } public void mouseReleased(MouseEvent e) { if(kujundivalik.getSelectedIndex()==1){ lisaPunkt(e.getX(), e.getY()); } repaint(); } void lisaVarv(){ Color c=varvid[varvivalik.getSelectedIndex()]; Element varv=d.createElement("varv"); Element punane=d.createElement("punane"); Element roheline=d.createElement("roheline"); Element sinine=d.createElement("sinine"); varv.appendChild(punane); varv.appendChild(roheline); varv.appendChild(sinine); punane.appendChild(d.createTextNode(String.valueOf(c.getRed()))); roheline.appendChild(d.createTextNode(String.valueOf(c.getGreen()))); sinine.appendChild(d.createTextNode(String.valueOf(c.getBlue()))); kujund.appendChild(varv); } void lisaPunkt(int x, int y){ Element punkt=d.createElement("punkt"); Element px=d.createElement("x"); px.appendChild(d.createTextNode(x+"")); punkt.appendChild(px); Element py=d.createElement("y"); py.appendChild(d.createTextNode(y+"")); punkt.appendChild(py); kujund.appendChild(punkt); } public void alusta(){ try{ d=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); juur=d.createElement("koordinaadid"); d.appendChild(juur); repaint(); } catch(Exception viga){System.out.println("Viga dokumendi loomisel: "+viga);} } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseMoved(MouseEvent e){} public static void main(String argumendid[]) throws Exception{ new XMLJoonis2(); } }