import java.awt.*; import java.awt.event.*; import java.util.*; public class Tuba extends Panel implements MouseListener{ LinkedList kujundid=new LinkedList(); Choice resiim=new Choice(); Choice ktyyp=new Choice(); Kujund pihtas; int hx, hy; public Tuba(){ resiim.addItem("Lisamine"); resiim.addItem("Liigutamine"); resiim.addItem("Kustutamine"); ktyyp.addItem("Ring"); ktyyp.addItem("Ristkylik"); add(resiim); add(ktyyp); addMouseListener(this); } public void paint(Graphics g){ for(Iterator it=kujundid.iterator(); it.hasNext();){ Kujund k=it.next(); k.joonista(g); } } public void mousePressed(MouseEvent e){ hx=e.getX(); hy=e.getY(); pihtas=null; for(Iterator it=kujundid.iterator(); it.hasNext();){ Kujund k=it.next(); if(k.kasPihtas(hx, hy)){pihtas=k;} } } public void mouseReleased(MouseEvent e){ if(resiim.getSelectedItem().equals("Liigutamine")){ if(pihtas!=null){ pihtas.paiguta(e.getX(), e.getY()); } } if(resiim.getSelectedItem().equals("Lisamine")){ int dx=e.getX()-hx; int dy=e.getY()-hy; if(ktyyp.getSelectedItem().equals("Ring")){ kujundid.add(new Kujund(hx, hy, dx)); } else { kujundid.add(new Kujund(hx, hy, dx, dy)); } } repaint(); } public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] arg){ Frame f=new Frame(); f.add(new Tuba()); f.setSize(300, 300); f.setVisible(true); } }