import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

// This is a pure-Java-1.1 variation of an example that
// appears in Core Web Programming from Prentice Hall
// Publishers. It may be freely used or adapted.
// 1997-99 Marty Hall, http://www.apl.jhu.edu/~hall/.

public class SearchService extends Applet implements ActionListener {
  private TextField searchField;
  protected String baseURL, serviceName, frame="Results";
  protected int textFieldSize = 30;
  
  public void setup() {
    Panel inputPanel = new Panel();
    inputPanel.add(new Label("Search String: "));
    searchField = new TextField(textFieldSize);
    inputPanel.add(searchField);
    add(inputPanel);
    Button submitButton = new Button("Submit to " + serviceName);
    submitButton.addActionListener(this);
    add(submitButton);
  }

  public void actionPerformed(ActionEvent event) {
    String searchString
      = URLEncoder.encode(searchField.getText());
    showSearch(searchString);
  }

  public void showSearch(String searchString) {
    try {
      URL url = new URL(baseURL + searchString);
      getAppletContext().showDocument(url, frame);
    } catch(MalformedURLException mue) {
      System.out.println("Illegal URL: " + baseURL
                         + searchString);
    }
  }
}
