import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="adapter" height=300 width=300></applet>*/
public class adapter extends Applet
{
int x,y;
String s;
Font f;
public void init()
{
s=" ";
f=new Font("Arial",Font.BOLD,13);
addMouseListener(new A());
addMouseMotionListener(new B());
}
class A extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
x=e.getX();
y=e.getY();
Cursor co=new Cursor(Cursor.CROSSHAIR_CURSOR);
setCursor(co); //method of Component
setForeground(Color.red);
s="mouse is clicked";
repaint();
}
}
class B extends MouseMotionAdapter
{
public void mouseMoved(MouseEvent e)
{
x=e.getX();
y=e.getY();
Cursor co=new Cursor(Cursor.HAND_CURSOR);
setCursor(co); //methods of Component
setForeground(Color.blue);
s="mouse is moved";
repaint();
}
}
public void paint(Graphics g)
{
g.setFont(f);
g.drawString(s,x,y);
}
}
import java.awt.event.*;
import java.applet.*;
/*<applet code="adapter" height=300 width=300></applet>*/
public class adapter extends Applet
{
int x,y;
String s;
Font f;
public void init()
{
s=" ";
f=new Font("Arial",Font.BOLD,13);
addMouseListener(new A());
addMouseMotionListener(new B());
}
class A extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
x=e.getX();
y=e.getY();
Cursor co=new Cursor(Cursor.CROSSHAIR_CURSOR);
setCursor(co); //method of Component
setForeground(Color.red);
s="mouse is clicked";
repaint();
}
}
class B extends MouseMotionAdapter
{
public void mouseMoved(MouseEvent e)
{
x=e.getX();
y=e.getY();
Cursor co=new Cursor(Cursor.HAND_CURSOR);
setCursor(co); //methods of Component
setForeground(Color.blue);
s="mouse is moved";
repaint();
}
}
public void paint(Graphics g)
{
g.setFont(f);
g.drawString(s,x,y);
}
}
No comments:
Post a Comment