/*
This class is a basic extension of the Applet class. It would generally be
used as the main class with a Java browser or the AppletViewer. But an instance
can be added to a subclass of Container. To use this applet with a browser or
the AppletViewer, create an html file with the following code:
Winpost window
You can add controls to Simple with Cafe Studio.
(Menus can be added only to subclasses of Frame.)
*/
import java.awt.*;
import java.io.*;
import java.net.*;
public class Winpost extends java.applet.Applet {
public void init() {
//{{INIT_CONTROLS
setLayout(null);
addNotify();
resize(insets().left + insets().right + 489, insets().top + insets().bottom + 108);
label1=new Label("Search:");
add(label1);
label1.reshape(insets().left + 9,insets().top + 8,63,22);
SearchText=new TextField(39);
add(SearchText);
SearchText.reshape(insets().left + 72,insets().top + 8,396,24);
Ultra=new Button("&Ultra");
add(Ultra);
Ultra.reshape(insets().left + 9,insets().top + 48,99,24);
AltaVista=new Button("&Altavista");
add(AltaVista);
AltaVista.reshape(insets().left + 126,insets().top + 48,101,24);
Yahoo=new Button("&Yahoo");
add(Yahoo);
Yahoo.reshape(insets().left + 243,insets().top + 48,99,24);
Deja=new Button("&Dejanews");
add(Deja);
Deja.reshape(insets().left + 360,insets().top + 48,108,24);
//}}
super.init();
}
public boolean handleEvent(Event event) {
if (event.id == Event.ACTION_EVENT && event.target == Deja) {
clickedDeja();
return true;
}
else
if (event.id == Event.ACTION_EVENT && event.target == Yahoo) {
clickedYahoo();
return true;
}
else
if (event.id == Event.ACTION_EVENT && event.target == AltaVista) {
clickedAltaVista();
return true;
}
else
if (event.id == Event.ACTION_EVENT && event.target == Ultra) {
clickedUltra();
return true;
}
return super.handleEvent(event);
}
//{{DECLARE_CONTROLS
Label label1;
TextField SearchText;
Button Ultra;
Button AltaVista;
Button Yahoo;
Button Deja;
//}}
public void SendQuery(String s) {
URL u = null;
try {
u = new URL(s + URLEncoder.encode(SearchText.getText()));
} catch (IOException MalformedURLException) {
System.out.println("Bad URL!");
return;
}
System.out.println(u.toString()); // Display the URL we're sending to debug
getAppletContext().showStatus("Getting " + u.toString());
getAppletContext().showDocument(u);
}
public void clickedUltra() { // User hit Infoseek Ultra
SendQuery("http://ultra.infoseek.com/Titles?nh=10&sv=US&lk=1&qt=");
}
public void clickedAltaVista() { // User hit Altavista
SendQuery("http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=");
}
public void clickedYahoo() { // User hit Yahoo
SendQuery("http://search.yahoo.com/bin/search?p=");
}
public void clickedDeja() { // User hit Dejanews
SendQuery("http://search.dejanews.com/dnquery.xp?maxhits=20&query=");
}
}