首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

Java学习二-17 事件

2013-11-08 
Java学习2-17事件? ?确定事件-事件监听-绑定? ?ActionListener,MouseListener,KeyListener,WindowListen

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());

?

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

?

?

热点排行