当前位置: 首页 > 图灵资讯 > 技术篇> ActionListener动作监听

ActionListener动作监听

来源:图灵教育
时间:2023-06-25 14:31:57

import javax.swing.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;//ActionListener:动作监控(点击鼠标,按下空间)public class Actionlistentertestttest1 {    public static void main(String[] args) {        JFrame f=new JFrame();        f.setSize(500,500);        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);        f.setLayout(null);        JButton jl1=new JButton(按钮);        jl1.setBounds(0,0,100,100);        f.getContentPane().add(jl1);        jl1.addActionListener(new ActionListener() {            @Override            public void actionPerformed(ActionEvent e) {                System.out.println(“我被点了!!!!");            }        });        f.setVisible(true);    }}