📄 actevent.java
字号:
import java.awt.*;
import java.awt.event.*;
public class ActEvent extends Frame implements ActionListener {
static ActEvent frm = new ActEvent();
static Button btn1, btn2;
static Label lbl;
public static void main(String args[]) {
frm.setTitle("ActionEvent");
frm.setSize(240, 160);
frm.setLayout(new FlowLayout());
btn1 = new Button(" button 1 ");
btn2 = new Button(" button 2 ");
lbl = new Label(" no clicking ");
btn1.addActionListener(frm);
btn2.addActionListener(frm);
frm.add(btn1);
frm.add(btn2);
frm.add(lbl);
frm.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1)
lbl.setText("button 1 clicked");
else
lbl.setText("button 2 clicked");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -