Monday, 3 November 2014

Create an applet to display coordinates of mouse movements in a text box.




Name : Shreyal Mandot

Title : Assignment 8a2. Create an applet to display coordinates of mouse movements in a text box.



import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*
<applet code="ass8a2.class" width=400 height=200>

</applet>
*/

public class ass8a2 extends Applet implements MouseMotionListener
{

int x=0,y=0;

public void init()
{

setBackground(Color.orange);
addMouseMotionListener(this);

}

public void paint(Graphics g)
{

String msg="X: "+x+" Y: "+y;
g.drawString(msg,10,10);

}
public void mouseDragged(MouseEvent e)
{



}
public void mouseMoved(MouseEvent e)
{

x=e.getX();
y=e.getY();
repaint();

}

}

No comments:

Post a Comment