package 图形界面;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class one extends JFrame {
Label lable = new Label("请单击按钮");
public one() {
setTitle("主窗口");
Container c = getContentPane();
setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
setSize(500, 200);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JButton j1 = new JButton("第2个按钮");
JButton j2 = new JButton("第1个按钮");
c.add(l);
c.add(j2);
c.add(j1);
j1.addActionListener(new jbn1());
j2.addActionListener(new jbn2());
setVisible(true);//设置窗口可见
}
class jbn1 implements ActionListener{
public void actionPerformed(ActionEvent e) {
lable.setText("你按了第2个按钮");
}
}
class jbn2 implements ActionListener{
public void actionPerformed(ActionEvent e) {
l.setText("你按了第1个按钮");
}
}
public static void main(String[] args) {
new one();
}
}