Event Concept

debut.cis.nctu.edu.tw
  • No tags were found...

Event Concept

• • • • • •


• ButtonOther object• • •


—• Source• • • Listener• •


—SourceListener• • • • • • • SourceActionEvent typeMouseEvent typeListener


• • public void actionPerformed(ActionEvent e) {. sourceListener}actionPerformed(…)


• • • • • • •


public interface ActionListener extends java.util.EventListener {public void actionPerformed(ActionEvent e);}• • • •


• ActionListenerActionListener ,• • • …•


ActionListenerEnter , ?• • • • • • •


, addActionListener(..)method Listener// ActionEvent JButton theButton= new JButton(“ ”);// ActionEvent class TheReceiver implements ActionListener {setupReceiver(){}…theButton.addActionListener(this); : ActionListener }public void actionPerformed( ActionEvent e) {// }


,removeActionListener Listen• • …• … • • •


• • • •


• • •


• • • •


• • • • •


• • •SHIFT_MASK•CTRL_MASK•META_MASK•ALT_MASK•BUTTON1_MASK•BUTTON2_MASK•BUTTON3_MASK


• public void mousePressed(MouseEvent e) {int mods = e.getModifiers();if((mods & InputEvent.SHIFT_MASK) !=0){, Shift !}}


• : :1. ActionListener 2.


class MyObject implement ActionListener {public void actionPerformed(…){}!}methodclass MyObject {1. method2.3.!}


• implement ActionListener {public void actionPerformed(…) {}class MyObject {1. method2.3. !}


class MyObject {public void OnPush() { // 3.!}}public MyObject(){. .addActionListener(new (this));}ass implement ActionListener {MyObject obj;public void actionPerformed(ActinEven e) {obj.Onpush();}public (MyObject obj) {this.obj=obj;}1

More magazines by this user
Similar magazines