- <p>import java.awt.*;
- import java.awt.event.*;</p><p>import javax.swing.*;</p><p>public class SimpleEvent extends JFrame{</p><p> /**
- *
- */
- private static final long serialVersionUID = 1L;
- private JButton jb=new JButton("我是按钮,单击我");
- private JButton jb2=new JButton("我是按钮2,单击我");
- public SimpleEvent(){
- setLayout(null);
- setSize(200,100);
- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- Container cp=getContentPane();
- cp.add(jb,jb2);
- jb.setBounds(10, 10,100,30);
- jb2.setBounds(10, 10,100,30);
- jb.addActionListener(this);
- jb2.addActionListener(this);
- setVisible(true);
- }
- public void actionPerformed(ActionEvent arg0) {
- jb.setText("我被单击了");
- }
- public void actionPerformed(ActionEvent arg0) {
- jb.setText("我也被单击了");
- }
- }
- public static void main(String[] args) {
- new SimpleEvent();
- }
- </p>
复制代码
这段代码运行出错了= =
|