import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class myfa { public static void main(String[] args) { myfam01 m=new myfam01(); m.setVisible(true);//让窗口设置为可见 } } class myfam01 extends JFrame{//jframe为常用的窗口属性类 private JButton BTU=new JButton("按钮1");//创建第一个按钮1 private JButton btu=new JButton("按钮2"); public myfam01() { //setVisible(true); setSize(300,400);//设置窗口的尺寸 setTitle("接口");//设置窗口的标题 setLayout(new FlowLayout());//设置窗口的布局 BTU.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { BTU.setLabel("HAHA"); } });//修改按钮被点击后出现的文字 btu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { btu.setLabel("ni"); }//调用鼠标监视器 }); add(BTU); add(btu); } }