import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

public class EggApplet extends Applet
{	public EggApplet()
	{	egg = new Ellipse2D.Double(0, 0, 
			EGG_WIDTH, EGG_HEIGHT);
		
		contorno = new Rectangle2D.Double();

		// aggiunge l'intercettatore del clic del mouse 

		MouseClickListener listener = new MouseClickListener();
		addMouseListener(listener);
	}

	public void paint(Graphics g)
	{	Graphics2D g2 = (Graphics2D)g;
//		contorno.setFrame(0, 0, this.getWidth(), this.getHeight());
		contorno.setFrame(0, 0, this.getWidth()-1, this.getHeight()-1);
		g2.draw(contorno);
		g2.draw(egg);
	}

	private Ellipse2D.Double egg;
	private static final double EGG_WIDTH = 30, EGG_HEIGHT = 50;
	
	private Rectangle2D.Double contorno;


	// definizione della classe interna

	private class MouseClickListener extends MouseAdapter
	{  public void mouseClicked(MouseEvent event)
		{  int mouseX = event.getX();
			int mouseY = event.getY();
System.out.print("CLICK! ");

			// sposta l'ellisse su (mouseX, mouseY)

			egg.setFrame(mouseX - EGG_WIDTH / 2,
				mouseY - EGG_HEIGHT / 2, EGG_WIDTH, EGG_HEIGHT);
			repaint();
		}
	}
}



Questa la bacheca di Informatica Grafica, corso di laurea specialistica in Ing. Edile-architettura
by FdA
ultima modifica: 02/02/2005 11.30