日期:2014-05-18 浏览次数:20710 次
package graphic;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.MouseListener;
import java.awt.TextField;
import java.awt.event.MouseEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
import java.awt.event.MouseMotionListener;
public class LisenerTest implements MouseListener,MouseMotionListener,
WindowListener
{
private Frame f;
private TextField tf;
public static void main(String[] args)
{
LisenerTest lt = new LisenerTest();
lt.go();
}
public void go()
{
f = new Frame("监听器样列!");
// System.out.println(f.getLayout().toString());
f.add(new Label("单击拖动鼠标"),"North");
tf = new TextField(30);
f.add(tf,"South");
f.addMouseListener(this);
f.addMouseMotionListener(this);
f.addWindowListener(this);
f.setSize(300,300);
f.setVisible(true);
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
String s = "鼠标坐标:X = "+e.getX()+" Y = " +e.getY();
tf.setText(s);
}
@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent e) {