Sunday, December 14, 2008

AWT(Label)

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

public class Mlabel extends Frame implements MouseMotionListener,WindowListener {

Label x1=new Label("X=");
Label x2=new Label(" ");
Label y1=new Label("Y=");
Label y2=new Label(" ");

Mlabel(){
super("Mouse Movent");
setSize(300,300);
setLayout(new FlowLayout());

add(x1);
add(x2);
add(y1);
add(y2);




addMouseMotionListener(this);
addWindowListener(this);
setVisible(true);

}


public void windowActivated(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowClosing(WindowEvent e){
System.exit(0);
}

public void windowDeactivated(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowOpened(WindowEvent e){}

public void mouseMoved(MouseEvent e){
int x=e.getX();
int y=e.getY();
String t1=" "+x;
String t2=" "+y;

x2.setText(t1);
y2.setText(t2);
}

public void mouseDragged(MouseEvent e){
int x=e.getX();
int y=e.getY();
String t1=" "+x;
String t2=" "+y;

x2.setText(t1);
y2.setText(t2);
}

public static void main(String[] ar){
Mlabel m=new Mlabel();
}
}

No comments:

Post a Comment