📄 testanonymous.java
字号:
import java.awt.*;
import java.awt.event.*;
public class TestAnonymous {
private Frame f;
private TextField tf;
public TestAnonymous() {
f = new Frame("Anonymous classes example");
tf = new TextField(30);
}
public void launchFrame() {
Label label = new Label("Click and drag the mouse");
// Add components to the frame
f.add(label, BorderLayout.NORTH);
f.add(tf, BorderLayout.SOUTH);
// Add a listener that uses an anonymous class
f.addMouseMotionListener( new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
String s = "Mouse dragging: X = "+ e.getX()
+ " Y = " + e.getY();
tf.setText(s);
}
}); // <- note the closing parenthesis
f.addMouseListener(new MouseClickHandler());
// Size the frame and make it visible
f.setSize(300, 200);
f.setVisible(true);
}
public static void main(String args[]) {
TestAnonymous obj = new TestAnonymous();
obj.launchFrame();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -