总结:最难的就是当我们需要点击按钮时去实现某个功能-----------因为那个我没有理解透,是涉及整个程序的
package com.a.b;
import javax.swing.*;
import java.awt.event.*;
class SB extends JFrame implements ActionListener {
JButton jb;
public SB() {
jb = new JButton("你你你");
jb.addActionListener(this);// 注册监听
this.setVisible(true);
this.add(jb);
this.setBounds(333, 333, 500, 500);
this.setDefaultCloseOperation(3);
}
public void actionPerformed(ActionEvent a) {
if (a.getSource() == jb) {
System.out.println("你好");
}
}
}
public class Shi {
public static void main(String[] args) {
new SB();
}
}