import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class kodune1 extends Applet implements MouseMotionListener, MouseListener{ int r=10; int k=0; int[] koordx=new int[100]; int[] koordy=new int[100]; public kodune1(){ addMouseMotionListener(this); addMouseListener(this); } public void mousePressed(MouseEvent e){ Graphics g=this.getGraphics(); if(k<100){ g.setColor(Color.red); g.fillOval(e.getX()-r, e.getY()-r, 2*r, 2*r); //x,y, kõrgus,laius koordx[k]=e.getX(); koordy[k]=e.getY(); k++; } } public void mouseMoved(MouseEvent e){ Graphics g=this.getGraphics(); for(int i=0; i<100; i++){ if(koordx[i]!=0 && koordy[i]!=0){ if((((koordx[i]-e.getX())*(koordx[i]-e.getX()))+ ((koordy[i]-e.getY())*(koordy[i]-e.getY())))>(r+100)*(r+100)){ g.setColor(Color.green); g.fillOval(koordx[i]-r, koordy[i]-r, 2*r, 2*r); } else{ g.setColor(Color.red); g.fillOval(koordx[i]-r, koordy[i]-r, 2*r, 2*r); } } } } public void mouseDragged(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new kodune1()); f.setSize(300, 300); f.setVisible(true); f.addWindowListener(new Raami2kuular()); } } class Raami2kuular extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.out.println(" "); System.exit(0); } }