Neste caso eu posso dizer que tenho o padrão Observer?
Se sim, teria dois observer (ActionListener)? isso?
[code]public class ObserverSwing {
private JFrame frame;
ArrayList<ActionListener> arr= new ArrayList();
public void iniObserver(){
frame = new JFrame();
JButton b = new JButton(“ola”);
ActionListener observer = new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println("fui add "+1);
}
};
addAction(observer);
addAction(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println("fui add "+2);
}
});
recupera(b);
frame.getContentPane().add(b);
frame.setVisible(true);
}
public void addAction(ActionListener a){
arr.add(a);
}
public void recupera(JButton bu){
for(ActionListener a: arr)
bu.addActionListener(a);
}
public static void main(String[]args){
new ObserverSwing().iniObserver();
}
}
[/code]