菜鸟提问
用匿名类 来 做事件处理
代码如下:
public class Three
{
private Frame f;
private TextField tf;
public void go()
{
f = new Frame("It is Inner class");
tf= new TextField(30);
f.add(tf,"South");
f.addMouseListener(new MouseAdapter(){
public void mouseEntered()
{
String s="Look,the mouse is coming!";
tf.setText(s);
}
public void mouseExited()
{
String s="Oh~~~,the mouse is left";
tf.setText(s);
}
} );
//注册监听器MouseListener
f.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e)
{
String s="The mouse dragging: x="+e.getX()+"y="+e.getY();
tf.setText(s);
}
});
//注册监听器WindowListener
f.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e)
{
System.exit(1);
}
});
f.setSize(400,400);
f.setVisible(true);
}
public static void main(String rags[])
{
Three t = new Three();
t.go();
}
}
但是只能实现 String s="The mouse dragging: x="+e.getX()+"y="+e.getY();
这句话 其他都不能实现
这是怎么回事啊???请老大 急救啊~~~ 不甚感激