%% -*- mode: latex; TeX-master: "informatik.tex"; -*-

\begin{slide}{Ereignis-Behandlung in Applets (I)}

\kopf{$ $Id: event.tex,v 1.2 2006-12-11 15:46:45 waldmann Exp $ $}

\begin{verbatim}
public class Click {   
  Label out = new Label ("");
  Button inc = nwe Button ("inc");
  Counter c = new Counter();
  ...
  public void init () {
    add (inc); add (out);
    ...
  }
} 
\end{verbatim}

\end{slide}



\begin{slide}{Ereignis-Behandlung in Applets (II)}

\kopf{$ $Id: event.tex,v 1.2 2006-12-11 15:46:45 waldmann Exp $ $}

\begin{verbatim}
public class Click { ...
 ...
 class Inc_Listen implements ActionListener {
  public void actionPerformed (ActionEvent a) {
    c.step(); out.setText (c.get());
  }
 }
 public void init () { ...
  inc.addActionListener (new Inc_Listen ());
 }
}
\end{verbatim}

\end{slide}

\begin{slide}{Ereignis-Behandlung in Applets (III)}

\kopf{$ $Id: event.tex,v 1.2 2006-12-11 15:46:45 waldmann Exp $ $}

empfohlene Schreibweise mit anonymer Klasse:

\begin{verbatim}
public class Click { ...
 public void init () { ...
  inc.addActionListener 
    (new ActionListener () {
      public void actionPerformed 
        (ActionEvent a) {
          c.step(); out.setText (c.get());
      } }
    )
} }
\end{verbatim}
Aufgaben: füge Knöpfe für \emph{decrement}
und \emph{reset} hinzu.

\end{slide}
