02 관찰자 모드 - Awt 시뮬레이션(2)

1948 단어 관찰자 모드
1.public class AWTSimulation {

	public static void main(String[] args) {
		Buttton b = new Buttton();
		
		
		b.addActionListener(new MyActionListener());
		b.addActionListener(new MyActionListener2());
		
		b.buttonPressed();
		
	}

}

/**
 *     
 * @author Administrator
 *
 */
class Buttton{
	List<ActionListener> actionListeners = new ArrayList<ActionListener>();
	
	public void buttonPressed(){
		ActionEvent actionEvent = new ActionEvent(System.currentTimeMillis(),this);
		
		for(ActionListener al : actionListeners){
			al.actionPerformed(actionEvent);
		}
		
		
	}
	
	public void addActionListener(ActionListener actionListener){
		actionListeners.add(actionListener);
	}
	
	
}

/**
 *    
 * @author Administrator
 *
 */
interface ActionListener{
	
	public void actionPerformed(ActionEvent actionEvent);
	
}

class MyActionListener implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent actionEvent) {
		System.out.println("actionPerformed 1.....");
	}
}

class MyActionListener2 implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent actionEvent) {
		System.out.println("actionPerformed 2.....");
	}
}

class ActionEvent{
	//      
	long when;
	
	//     
	Object source;

	public ActionEvent(long when,Object source) {
		this.source = source;
		this.when = when;
	}
	
	public long getWhen(){
		return when;
	}
	
	public Object getSource(){
		return source;
	}
	
	
	
	
	
}

좋은 웹페이지 즐겨찾기