public class TwoListenInner
{
private Frame f;
private TextField tf;
public static void main(String args[]){
TwoListenInner That=new TwoListenInner();
}
public TwoListenInner(){
f=new Frame("Two listeners example");
f.add("North",new Label("Click and drag the mouse"));
f.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
tf=new TextField(30);
f.add("South",tf);
f.addMouseMotionListener(new MouseMotionHandler());
f.addMouseListener(new MouseEventHandler());
f.setSize(300,300);
f.setEnabled(true);
f.setVisible(true);
}
public class MouseMotionHandler extends MouseMotionAdapter{
public void mouseDragged(MouseEvent e){
String s="Mouse dragging: X="+e.getX()+"Y="+e.getY();
tf.setText(s);
}
}
public class MouseEventHandler extends MouseAdapter{
public void mouseEntered(MouseEvent e){
String s="The mouse entered";
tf.setText(s);
}
public void mouseExited(MouseEvent e){
String s="The mouse has left the building";
tf.setText(s);
}
}
}
public class TwoListenInner
{
private Frame f;
private TextField tf;
public static void main(String args[]){
TwoListenInner That=new TwoListenInner();
}
public TwoListenInner(){
f=new Frame("Two listeners example");
f.add("North",new Label("Click and drag the mouse"));
tf=new TextField(30);
f.add("South",tf);
f.addMouseMotionListener(new MouseMotionHandler());
f.addMouseListener(new MouseEventHandler());
f.setSize(300,300);
f.setEnabled(true);
f.setVisible(true);
}
public class MouseMotionHandler extends MouseMotionAdapter{
public void mouseDragged(MouseEvent e){
String s="Mouse dragging: X="+e.getX()+"Y="+e.get();
tf.setText(s);
}
}
public class MouseEventHandler extends MouseAdapter{
public void mouseEntered(MouseEvent e){
String s="The mouse entered";
tf.setText(s);
}
public void mouseExited(MouseEvent e){
String s="The mouse has left the building";
tf.setText(s);
public class MyApp333 extends Frame
{
public MyApp333()
{
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public static void main(String args[])
{
System.out.println("Starting App");
MyApp333 f = new MyApp333();
f.setSize(100,100);
f.show();
}
}