Sunday, 3 June 2012

Events programming

import java.awt.*;
import java.awt.event.*;
public  class  twoevents  implements  MouseListener,MouseMotionListener
{
public  Frame f;
public  TextField  tf;
public TextField tf1;
public  Label  l;
public  Panel p;
String s;

 twoevents()
{
f=new Frame("mouseLinstener and mouseMotionListener events");
f.setSize(500,500);
tf=new TextField(30);
l=new Label("click and drag mouse");
tf1= new TextField(30);
p=new Panel();

}
public  void  looks()
{
f.add(l,BorderLayout.NORTH);
f.add(p,BorderLayout.SOUTH);
p.add(tf,BorderLayout.SOUTH);
p.add(tf1,BorderLayout.NORTH);
f.addMouseListener(this);
f.addMouseMotionListener(this);
f.setVisible(true);
}

public void  mouseEntered(MouseEvent e)
{
 String s="Mouse Enter...";
tf.setText(s);
}
public  void mouseExited(MouseEvent e)
{
String s="mouse  run away form frame";
tf.setText(s);
}

public  void mousePressed(MouseEvent e)
{
}
public  void mouseReleased(MouseEvent e)
{
}
public  void mouseClicked(MouseEvent e)
{
}
public  void mouseMoved(MouseEvent  e)
{
s="maouse  moveing :X"+e.getX()+"  : y is:"+e.getY();
tf1.setText(s);
}
public  void mouseDragged(MouseEvent e)
{
}
public  static  void  main(String  ar[])
{
twoevents  two = new twoevents();
two.looks();
}
}



No comments:

Post a Comment