java事件监听

获取事件监听需要获取实现ActionListener接口的方法,

public class SimpleEvent extends JFrame{
    private JButton jb=new JButton("我是按钮,点击我");
    public SimpleEvent(){
        setLayout(null);
        setVisible(true);
        setSize(200, 100);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container c=getContentPane();
        c.add(jb);
        jb.setBounds(10, 10, 300, 30);
        jb.addActionListener(new jbAction());
        
        
        
    }
    class jbAction implements ActionListener{

@Override
        public void actionPerformed(ActionEvent e) {
            jb.setText("我被点击了");
        }
        
        
        
    }
    public static void main(String[] args) {
        new SimpleEvent();
    }
}

上一篇:postgresql 触发器 更新操作


下一篇:Python基础:二、python介绍