import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.LinkedList; public class click extends Applet implements MouseListener, MouseMotionListener { LinkedList rings = new LinkedList(); public click(){ addMouseListener(this); addMouseMotionListener(this); } public boolean this_ring(myRing ring, int x, int y) { //System.out.println("x: " + x + "; y: " + y + "; ring.x: " + ring.x + "; ring.y: " + ring.y); int xvahe = x - ring.x; int yvahe = y - ring.y; if (xvahe <= 10 && xvahe >= 0 && yvahe <= 10 && yvahe >= 0) return true; else return false; } public void paint(Graphics g){ for (int i = 0; i < rings.size(); i++) { myRing ring = (myRing)rings.get(i); g.drawOval(ring.x, ring.y, 10, 10); } } public void mousePressed(MouseEvent e) { boolean caught = false; if (rings.size() == 0) rings.add(new myRing(e.getX(), e.getY())); else { for (int i = 0; i < rings.size(); i++) { myRing ring = (myRing)rings.get(i); if (this_ring(ring, e.getX(), e.getY())) { caught = true; break; } } if (!caught) rings.add(new myRing(e.getX(), e.getY())); } repaint(); } public void mouseDragged(MouseEvent e) { myRing ring = null; for (int i = 0; i < rings.size(); i++) { if (this_ring((myRing)rings.get(i), e.getX(), e.getY())) { ring = (myRing)rings.get(i); break; } } if (ring != null) { ring.x = e.getX() - 5; ring.y = e.getY() - 5; 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){} public static void main(String[] argumendid) { Frame f=new Frame(); f.add(new click()); f.setSize(200, 200); f.setTitle("Click!"); f.setVisible(true); f.addWindowListener(new React()); } } class myRing { int x; int y; public myRing(int newx, int newy) { x = newx - 5; y = newy - 5; } } class React extends WindowAdapter { public void windowClosing(WindowEvent mywindow) { System.out.println("Closed"); System.exit(0); } }