FileDocCategorySizeDatePackage
whoisApplet.javaAPI DocExample5489Thu Apr 03 15:24:02 BST 1997None

whoisApplet

public class whoisApplet extends Applet

Fields Summary
public static final int
port
public static final String
hostname
TextField
searchString
TextArea
detailView
List
names
Button
findButton
CheckboxGroup
searchIn
CheckboxGroup
searchFor
Checkbox
exactMatch
Constructors Summary
Methods Summary
public booleanaction(java.awt.Event e, java.lang.Object o)

  
    if (e.target == searchString || e.target == findButton) {
      lookUpNames(searchString.getText());
      return true;
    }
    else if (e.target == names) {
      getFullRecord(names.getSelectedItem());
      return true;
    }
    else {
      return false;
    }
  
  
public voidgetFullRecord(java.lang.String summary)

  
    Socket theSocket;
    DataInputStream theWhoisStream;    
    PrintStream ps;
    String s;
    String handle = getHandle(summary);
  
    try {
      theSocket = new Socket(hostname, port, true);
      ps = new PrintStream(theSocket.getOutputStream());
      theWhoisStream = new DataInputStream(theSocket.getInputStream());
      ps.print("!" + handle + "\r\n");
      detailView.setText("");
      while ((s = theWhoisStream.readLine()) != null) {
        detailView.appendText(s + "\n");
      }
    }  
    catch (IOException e) {
      System.err.println(e);
    }
  
  
java.lang.StringgetHandle(java.lang.String s)

  
    int begin = s.indexOf("(") + 1;
    int end = s.indexOf(")", begin);
    
    return s.substring(begin,end);
  
  
public voidinit()

  
    setLayout(new BorderLayout());
    // The TextArea in the center will expand to fill the
    // center of the BorderLayout
    detailView = new TextArea(12, 40);
    detailView.setEditable(false);
    names = new List(12, false);
    Panel CenterPanel = new Panel();
    CenterPanel.setLayout(new GridLayout(1, 2, 10, 10));
    CenterPanel.add("Center", names);
    CenterPanel.add(detailView);
    add("Center", CenterPanel);   
    
    // You don't want the buttons in the south and north
    // to fill the entire sections so add Panels there
    // and use FlowLayouts in the Panel
    Panel NorthPanel = new Panel();
    Panel NorthPanelTop = new Panel();
    NorthPanelTop.setLayout(new FlowLayout(FlowLayout.LEFT));
    NorthPanelTop.add(new Label("Whois: "));
    searchString = new TextField(30);
    NorthPanelTop.add("North", searchString);
    exactMatch = new Checkbox("Exact Match", null, true);
    NorthPanelTop.add(exactMatch);
    NorthPanel.setLayout(new BorderLayout(2,1));
    NorthPanel.add("North", NorthPanelTop);
    Panel NorthPanelBottom = new Panel();
    NorthPanelBottom.setLayout(new GridLayout(1,2,5,5));
    NorthPanelBottom.add(initRecordType());
    NorthPanelBottom.add(initSearchFields());
    NorthPanel.add("Center", NorthPanelBottom);
    Panel SouthPanel = new Panel();
    findButton = new Button("Find");
    SouthPanel.add("South", findButton);
    add("South", SouthPanel);
    add("North", NorthPanel);
      
  
public java.awt.PanelinitRecordType()

  
    Panel p = new Panel();
    p.setLayout(new GridLayout(6, 2, 5, 2));
    searchFor = new CheckboxGroup();
    p.add(new Label("Search for:"));
    p.add(new Label(""));
    p.add(new Checkbox("Any", searchFor, true));
    p.add(new Checkbox("Network", searchFor, false));
    p.add(new Checkbox("Person", searchFor, false));
    p.add(new Checkbox("Host", searchFor, false));
    p.add(new Checkbox("Domain", searchFor, false));
    p.add(new Checkbox("Organization", searchFor, false));
    p.add(new Checkbox("Group", searchFor, false));
    p.add(new Checkbox("Gateway", searchFor, false));
    p.add(new Checkbox("ASN", searchFor, false));
    return p;
  
  
public java.awt.PanelinitSearchFields()

  
    Panel p = new Panel();
    p.setLayout(new GridLayout(6, 1, 5, 2));
    searchIn = new CheckboxGroup();
    p.add(new Label("Search In:"));
    p.add(new Checkbox("All", searchIn, true));
    p.add(new Checkbox("Name", searchIn, false));
    p.add(new Checkbox("Mailbox", searchIn, false));
    p.add(new Checkbox("Handle", searchIn, false));
    return p;
  
  
public voidlookUpNames(java.lang.String name)

  
    Socket theSocket;
    DataInputStream theWhoisStream;    
    PrintStream ps;
    String s;
    
    try {
      theSocket = new Socket(hostname, port, true);
      ps = new PrintStream(theSocket.getOutputStream());
      theWhoisStream = new DataInputStream(theSocket.getInputStream());
      ps.print(makePrefix() + searchString.getText() + makeSuffix() + "\r\n");
      names.clear();
      while ((s = theWhoisStream.readLine()) != null) {
        names.addItem(s);
      }
    }  
    catch (IOException e) {
      System.err.println(e);
    }

  
public static voidmain(java.lang.String[] args)


       
  
    whoisApplet a = new whoisApplet();
    a.init();
    a.start();
  
    Frame appletFrame = new Frame("whois");
    appletFrame.add("Center", a);
    appletFrame.resize(500,300);
    appletFrame.move(50,50);
    appletFrame.show();

  
public java.lang.StringmakePrefix()

  
    String searchForLabel = searchFor.getCurrent().getLabel() + " ";
    String searchInLabel = searchIn.getCurrent().getLabel() + " ";
    if (searchInLabel.startsWith("A")) searchInLabel = ""; 
    if (searchForLabel.startsWith("A")) searchForLabel = ""; 
    return searchForLabel + searchInLabel + "$";
  
  
public java.lang.StringmakeSuffix()

  
    String suffix = "";
    if (!exactMatch.getState()) suffix = "."; 
    return suffix;