package com.itheima;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JFrame11 {
public static void main(String[] args) {
JFrame jf=new JFrame();
jf.setTitle("事件监听机制");
jf.setSize(400,300);
jf.setDefaultCloseOperation(3);
jf.setLocationRelativeTo(null);
jf.setAlwaysOnTop(true);
jf.setLayout(null); //取消窗体的默认布局
//创建按钮
JButton jButton=new JButton("你点我啊");
jButton.setBounds(0,0,100,100);
jf.add(jButton);
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("你过来啊");
}
});
//添加按钮到窗体中
jf.setVisible(true);
}
}
标签:JAVA,public,监听,jButton,new,import,jf,机制
From: https://www.cnblogs.com/cy-xt/p/16840245.html