package com.zhijun.test;
import java.util.ArrayList;
import java.util.List;
public class TestButton {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Button b = new Button();
b.addActionListener(new MyActionListener());
b.buttonPressed();
}
}
class Button {
private List<ActionListener> actionListeners = new ArrayList<ActionListener>();
public void buttonPressed() {
ActionEvent e = new ActionEvent();
for(int i=0; i<actionListeners.size(); i++) {
ActionListener l = actionListeners.get(i);
l.actionPerformed(e);
}
}
public void addActionListener(ActionListener l) {
actionListeners.add(l);
}
}
interface ActionListener {
public void actionPerformed(ActionEvent e);
}
class MyActionListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("button pressed!");
}
}
class ActionEvent {
public long getWhen() {
return System.currentTimeMillis();
}
}
10-05