📄 testactionevent2.java
字号:
package gui;
import javax.swing.*;
import java.awt.event.*;
public class TestActionEvent2 {
private static JFrame f;
private static JButton b1, b2;
public static void main(String args[]) {
f = new JFrame("Test");
b1 = new JButton("Start");
b2 = new JButton("Stop");
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println("start");
}
});
b1.addMouseListener(new MouseAdapter(){
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println("stop");
}
});
// b2.setActionCommand("game over");
f.add(b1, "North");
f.add(b2, "Center");
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -