📄 5-14.txt
字号:
import java.awt.*;
import java.awt.event.*;
public class TwoListenInner{
private Frame f;
private TextField tf;
public static void main(String ars[]){
TwoListenInner that = new TwoListenInner();
that.go();
}
public void go(){
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, 200);
f.setVisible(true);
}
// MouseMotionHandler 为一个内部类
public class MouseMotionHandler extends MouseMotionAdapter{
public void mouseDragged (MouseEvent e){
String s="Mouse dragging: X="+e.getX() +"Y="+e.getY();
tf.setText(s);
}
}
// MouseEventHandler
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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -