16.11.2013 Aufrufe

Programmieren in Java - HostFiXX.de

Programmieren in Java - HostFiXX.de

Programmieren in Java - HostFiXX.de

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

<strong>Programmieren</strong> <strong>in</strong> <strong>Java</strong><br />

{<br />

public void actionPerformed(ActionEvent ae)<br />

{<br />

Str<strong>in</strong>g s = e<strong>in</strong>gabeTextFeld.getText();<br />

ausgabeTextFeld.setText(s);<br />

}<br />

}<br />

public static void ma<strong>in</strong>(Str<strong>in</strong>g args[])<br />

{<br />

Vorl11b vorl11b = new Vorl11b();<br />

vorl11b.addW<strong>in</strong>dowListener(new W<strong>in</strong>dowAdapter()<br />

{<br />

public void w<strong>in</strong>dowClos<strong>in</strong>g(W<strong>in</strong>dowEvent e)<br />

{<br />

System.exit(0);<br />

}<br />

});<br />

}<br />

}<br />

Schließlich kann das Interface auch direkt implementiert wer<strong>de</strong>n.<br />

Zweckmäßigerweise ist dann die Anwendung e<strong>in</strong>e Subklasse von Frame.<br />

import java.lang.*;<br />

import java.awt.*;<br />

import java.awt.event.*;<br />

public class Vorl11a extends Frame implements ActionListener<br />

{<br />

private static Label e<strong>in</strong>gabeTextFeldLabel = new Label("E<strong>in</strong>gabestr<strong>in</strong>g:");<br />

private static TextField e<strong>in</strong>gabeTextFeld = new TextField(20);<br />

private static Label ausgabeTextFeldLabel = new Label("Ausgabestr<strong>in</strong>g:");<br />

private static TextField ausgabeTextFeld = new TextField(20);<br />

public Vorl11a()<br />

{<br />

e<strong>in</strong>gabeTextFeld.setEditable(true);<br />

ausgabeTextFeld.setEditable(false);<br />

Panel panel = new Panel();<br />

panel.add(e<strong>in</strong>gabeTextFeldLabel); panel.add(e<strong>in</strong>gabeTextFeld);<br />

panel.add(ausgabeTextFeldLabel); panel.add(ausgabeTextFeld);<br />

e<strong>in</strong>gabeTextFeld.addActionListener(this);<br />

add(panel);<br />

pack();<br />

setVisible(true);<br />

}<br />

public void actionPerformed(ActionEvent ae)<br />

{<br />

System.out.pr<strong>in</strong>tln(ae.getActionCommand());<br />

Str<strong>in</strong>g s = e<strong>in</strong>gabeTextFeld.getText();<br />

ausgabeTextFeld.setText(s);<br />

}<br />

public static void ma<strong>in</strong>(Str<strong>in</strong>g args[])<br />

{<br />

Vorl11a vorl11a = new Vorl11a();<br />

vorl11a.addW<strong>in</strong>dowListener(new W<strong>in</strong>dowAdapter()<br />

{<br />

public void w<strong>in</strong>dowClos<strong>in</strong>g(W<strong>in</strong>dowEvent e)<br />

{<br />

System.exit(0);<br />

}<br />

});<br />

}<br />

}<br />

210

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!