
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import netscape.javascript.*; /* LiveConnect */

/**
 * Zugriff auf JavaScript-Funktionen.
 * @author  Mark Donnermeyer
 */
public class AppletSetParam extends Applet implements ActionListener {
    
    private TextField text;
    
    /**
     * Initialisiert das Applet.
     */
    public void init() {
        
        setBackground(Color.white);
        Button set = new Button("Text setzen");
        set.setActionCommand("set");
        set.addActionListener(this);
        Button reset = new Button("Text löschen");
        reset.setActionCommand("reset");
        reset.addActionListener(this);
        
        text = new TextField("");
        text.setColumns(30);
        
        Panel input = new Panel(new FlowLayout(FlowLayout.LEFT));
        input.add(new Label("Bitte Text setzen"));
        input.add(text);
        
        Panel buttons = new Panel(new FlowLayout(FlowLayout.LEFT));
        buttons.add(set);
        buttons.add(reset);
        
        setLayout(new BorderLayout());
        add("Center", input);
        add("South", buttons);
    }

    /**
     * Es wurd ein Button gedrückt. Entsprechende Aktion 
     * durchführen und Text in ein HTML-Textfeld kopieren.
     */
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("reset"))
            text.setText("");

        // Hier spielt die Musik: Es wird ein JSObject als
        // Referenz auf die HTML-Seite gelesen und die 
        // JS-Methode setText(String) aufgerufen.
        JSObject win = JSObject.getWindow(this);
        String []args = new String[1];
        args[0] = text.getText();
        win.call("setText", args);
    }
    
}
