import trees.*;import queues.*;import lists.*;import java.io.*;import javax.swing.*;import java.util.*;public class WebCrawler{ public static final int MAX_SIZE = 1000; public static void main(String[] args) throws IOException { // Tree to store found Email Addresses BinarySearchTree emailTree = new BinarySearchTree(); // Priority Queue to store URLs //PriQueueInterface urlQ = new Heap(MAX_SIZE); //BoundedQueueInterface urlQ = new ArrayBndQueue(MAX_SIZE); // Sorted List of Processed URLS SortedListInterface toVisit = new ArraySortedList2(); // Sorted List of Visited URLS SortedListInterface visited = new ArraySortedList2(); // Boolean to control the program loop boolean continueSearching = true; // URLString object for the first URL to parse URLString nextURL = new URLString(JOptionPane.showInputDialog("Enter a URL")); do { if (!visited.contains(nextURL)) { PageParser newPage = new PageParser(nextURL); visited.add(nextURL); try { newPage.parse(); EmailAddress[] emailAddresses = newPage.getEmails(); for (int i = 0; i < emailAddresses.length; i++) if(!emailTree.contains(emailAddresses[i])) emailTree.add(emailAddresses[i]); URLString[] urlStrings = newPage.getUrls(); for (int i = 0; i < urlStrings.length; i++) toVisit.add(urlStrings[i]); //System.out.println("Emails from "+nextURL+": "+Arrays.toString(emailAddresses)); //System.out.println("URLS from "+nextURL+": "+Arrays.toString(urlStrings)); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Error loading page"); } } nextURL = (URLString) toVisit.getNext(); int choice = JOptionPane.showConfirmDialog(null, "Do you want to see all emails so far?", "View emails?", JOptionPane.YES_NO_OPTION); if(choice == JOptionPane.YES_OPTION) { emailTree.reset(BinarySearchTree.INORDER); String emailString = ""; for(int i = 0; i < emailTree.size(); i++) emailString += emailTree.getNext(BinarySearchTree.INORDER)+"\n"; JOptionPane.showMessageDialog(null, emailString); } choice = JOptionPane.showConfirmDialog(null, "Do you want to continue to \n" + nextURL, "Continue?", JOptionPane.YES_NO_OPTION); continueSearching = (choice == JOptionPane.YES_OPTION); } while (continueSearching); JOptionPane.showMessageDialog(null, "Min Email: "+emailTree.getMin()); JOptionPane.showMessageDialog(null, "Max Email: "+emailTree.getMax()); }}