📄 testbutton.java
字号:
import java.awt.*;
import java.awt.event.* ;
public class TestButton{
public static void main(String args[ ]){
Frame f = new Frame("Test");
f.setSize(200,100);
f.setLayout(new FlowLayout(FlowLayout.CENTER));
Button b = new Button("Press Me!");
b.addActionListener(new ButtonHandler( )); //注册点击鼠标事件监听器。
f.add(b);
f.setVisible(true) ;
}
}
//定义ActionEvent监听器类
class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
System.out.println("Action occurred");
System.out.println("Button's label is:"+
e.getActionCommand());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -