<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">   
import java.awt.*;

import java.util.*;

/** This class provides a GUI: a window with several int fields, double 
   fields, and text fields and a button. The current version has 3 int fields,
   0 double fields, and 3 String fields. Change the constructor call in method
   main to change the number of fields.
   
   Whenever the button in the window is pressed, method buttonPressed is called.
   */
public class MyJLiveWindow extends JLiveWindow {
   static Webpage wp;
  
   /** Place code in the body of this method to process fields and store 
    results in fields. Use&lt;br&gt;&lt;br&gt;
        
      getIntField(i)     for the number in int    field i; 0 is first field&lt;br&gt;
      getdoubleField(i)  for the number in double field i; 0 is first field&lt;br&gt;
      getStringField(i)  for the number in String field i; 0 is first field&lt;br&gt;
      setIntField(i,v);      to store int value v in field i&lt;br&gt;
      setDoubleField(i,v);   to store double value v in field i&lt;br&gt;
      setStringField(i,v);   to store String value v in field i&lt;br&gt;&lt;br&gt;

      Read in the first String field u (say) and the second String field p
      (say), both of which should be URLs. Print in the Java console the set
      of all links that are reachable from u and that have p as a prefix.
      
      This particular implementation of method buttonPressed is a testdriver for
      Assignment 5.
    */
   public Object buttonPressed() {
      String u= getStringField(0);  // start URL
      String p= getStringField(1);  // prefix
      LinkChecker lc= new LinkChecker(u,p);
      Set links= lc.getLinks();
      System.out.println("Number of links: " + links.size());
      
      Webpage wp= new Webpage(u);
      if (u == null) {
         System.out.println("u does not have protocol http or ftp or does not" +
               "have suffix htm or html or doesn't exist");
        return null;
      }
      
      System.out.println("Number of links: " + links.size());

      // Print the links on the Java console
         System.out.println("Here come the links");
         Enumeration e= links.elements();
         while (e.hasMoreElements()) {
            String x= (String) e.nextElement();
            System.out.println(x);
         }
         System.out.println("End of links");
      
      return null;
   }
 
   /** Create an instance of me and show it*/
   public static void main(String args[]) {
      // The first argument to MyJLiveWindow is the number of int fields,
      // the second argument is the number of double fields, and
      // the third argument is the number of text (or String) fields.
      MyJLiveWindow testJLiveWindow= new MyJLiveWindow(0, 0, 3);
      testJLiveWindow.showWindow();
   }
  
   /** Create my window with&lt;br&gt;
       max( min(i,MAX_FIELDS), 0) integer fields,&lt;br&gt;
       max( min(d,MAX_FIELDS), 0) double fields, and&lt;br&gt;
       max( min(s,MAX_FIELDS), 0) String fields&lt;br&gt;
       and a "ready" button
     */
   public MyJLiveWindow(int i, int d, int s) {
      super(i, d, s);
   }
}

</pre></body></html>