Hi vanitha
this the code which will move the square with mouse
-----------u need to run it in browser(
applet)-----------
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class first extends Applet
{
public
String mycolor;
public int rectx,recty,cursorx,cursory;
Image myImage;
public void init()
{
System.out.println("in init");
mycolor= getParameter("color");
enableEvents (MouseEvent.MOUSE_PRESSED|MouseEvent.MOUSE_DRAGGED|MouseEvent.MOUSE_RELEASED);
//to show the image
myImage = getImage (getCodeBase(),"c://images//client.gif");
}
public void paint(Graphics g)
{
g.drawString("Drag the rect",150,150);
g.drawRect(rectx,recty,100,100);
g.setColor (Color.blue);
g.fillRect (rectx,recty,100,100);
System.out.println(myImage);
g.drawImage (myImage,50,50, 100, 100, this);
}
public void processMouseEvent (MouseEvent evt)
{
if (evt.getID() == MouseEvent.MOUSE_PRESSED)
{
cursorx = evt.getX() - rectx;
cursory = evt.getY() - recty;
}
else if (evt.getID() == MouseEvent.MOUSE_RELEASED )
{
int x = evt.getX(), y = evt.getY();
Dimension sz = getSize ();
if (x < 0)<br /> x = 0;<br /> else if (x >= sz.width)
x = sz.width - 1;
if (y < 0)<br /> y = 0;<br /> else if (y >= sz.height)
y = sz.height - 1;
rectx = x - cursorx;
recty = y - cursory;
repaint ();
}//end elseif
}//end process mouse event
public void processMouseMotionEvent (MouseEvent evt)
{
if (evt.getID() == MouseEvent.MOUSE_DRAGGED )
{
// Set the x,y coordinates to the current locatioin and
// request the browser to repaint the window.
rectx = evt.getX() - cursorx;
recty = evt.getY() - cursory;
repaint ();
}
}//end processMouseMotionEvent
public void distroy()
{
System.out.println("in distroy");
}
}
------------------here is HTML code------------------------------<html>
< head>
< applet code="first.class" height=300 width=300>
< param name=color value=blue>
< param name=size value=100>
< /applet>
< /head>
< /html>
----------------------
bye
Ajit Kanada
(edited by Cindy to put spaces in html commands so that they would display instead of executing)
[This message has been edited by Cindy Glass (edited April 17, 2001).]