import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class HiirPallid3 extends JPanel implements MouseListener, MouseMotionListener{ java.util.List pallid=new ArrayList(); JComboBox tyybivalik=new JComboBox(); int hx, hy; public HiirPallid3(){ addMouseListener(this); addMouseMotionListener(this); tyybivalik.addItem("Tavaline pall"); tyybivalik.addItem("Hele pall"); tyybivalik.addItem("Kandiline pall (pakk)"); setLayout(new BorderLayout()); add(tyybivalik, BorderLayout.SOUTH); } public void paintComponent(Graphics g){ super.paintComponent(g); for(Pall p: pallid){ int k=(int)p.kaugus(hx, hy); if(k>220){k=220;} g.setColor(new Color(k, k, k)); p.joonista(g); } } public void mousePressed(MouseEvent e){ Pall otsitav=null; for(Pall p: pallid){ if(p.kasPihtas(e.getX(), e.getY())){ otsitav=p; } } if(otsitav!=null){ pallid.remove(otsitav); } else { if(tyybivalik.getSelectedIndex()==0){ pallid.add(new Pall(e.getX(), e.getY())); } if(tyybivalik.getSelectedIndex()==1){ pallid.add(new HelePall(e.getX(), e.getY())); } if(tyybivalik.getSelectedIndex()==2){ pallid.add(new Pakk(e.getX(), e.getY())); } } repaint(); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseMoved(MouseEvent e){ hx=e.getX(); hy=e.getY(); repaint(); } public void mouseDragged(MouseEvent e){} public static void main(String[] arg){ JFrame f=new JFrame("Palliaken"); f.getContentPane().add(new HiirPallid3()); f.setSize(400, 300); f.setVisible(true); } }