// 通过接口实现监听器
public class ActionMonitor extends JFrame implements ActionListener{
JButton button;
public ActionMonitor(){
this.setLayout(null);//布局
this.setSize(500,400);//大小
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置可以关闭
button =new JButton();
button.setBounds(200, 200, 100, 20);//位置和大小
button.addActionListener(this);//添加监听
this.add(button);
}
@Override
public void actionPerformed(ActionEvent e) {
// 监听动作
if(e.getSource()==button){
}
}
public static void main(String[] args) {
ActionMonitor am= new ActionMonitor();
}
}
监听器接口(三)
最新推荐文章于 2022-02-18 17:09:37 发布