MVC-Beispiel

public class View implements Observer {
    private Label l = new Label("undefined");
    Component getComponent() { return this.l; }
    public void update(Observable o, Object arg) {
        this.l.setText(Integer.toString(((Counter) o).getCount()));
}   }
public class Simple_MVC_Applet extends Applet {
    Button b = new Button ("step");
    Counter c = new Counter (); View v = new View ();
    public void init () {
        this.add (b); this.add(v.getComponent());
        c.addObserver(v);
        b.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              c.step();                
            } }); } }



Johannes Waldmann 2008-06-18