[java]代码库
import java.awt.*;
import java.awt.event.*;
public class AnonymousClass {
private Frame f;
private TextField tf;
public AnonymousClass() {
f = new Frame("Inner classes example");
tf = new TextField(30);
}
public void launchFrame() {
Label label = new Label("Click and drag the mouse");
f.add(label, BorderLayout.NORTH);
f.add(tf, BorderLayout.SOUTH);
f.addMouseMotionListener(new MouseMotionAdapter() { // 匿名类开始
public void mouseDragged(MouseEvent e) {
String s = "Mouse dragging: x=" + e.getX() + "Y=" + e.getY();
tf.setText(s);
}
}); // 匿名类结束
f.setSize(300, 200);
f.setVisible(true);
}
public static void main(String args[]) {
AnonymousClass obj = new AnonymousClass();
obj.launchFrame();
}
}