📄 twolisteninner.java
字号:
import java.awt.*;
import java.awt.event.*;
public class TwoListenInner
{
private Frame f;
private TextField tf;
public static void main(String args[])
{
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,300);
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 left the building";
tf.setText(s);
}
}
//基类对象可以由子类对象实现
//虽然interface是一个抽象类,但是它的实现必须使用implements关键字
//另外,在实现接口时,类中的函数返回值类型、函数名称、参数列表必须完全一致,只是不同类的函数体不同,当然,参数名称可以不一样
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -