Java学习2-17 事件

   确定事件->事件监听->绑定

   ActionListener,MouseListener,KeyListener,WindowListener

   eg:简单的button按钮触发事件导致窗体改变颜色

        可以用内部类来实现事件,再绑定

       1.在构造器里面设置。this.setLayout(new FlowLayout()

       2.添加按钮。             jb_Red = new JButton("Red");

       3.把按钮添加到窗体。this.getContentPane().add(jb_Red);

       4. 事件

           if (e.getActionCommand().equals("Red")) {

    ActionLis.this.getContentPane().setBackground(Color.red);}

       5.绑定 。           jb_Red.addActionListener(new ActionListenerimpl());

   事件重在理解,应该多加练习。周末把前面的课程再练习几次。

猜你喜欢

转载自loginpw.iteye.com/blog/1409840
今日推荐