import java.io.*;
import java.net.*;
import javax.swing.*;
/**
*Prints the Intro and the instructions for the user. Stores the user's input.
*Sends all the addresses to the callsWebClient method in order to eliminate code lines.
*/
public class WebClientTester
{
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException
{
WebClient address=new WebClient();
String addr1 ="http://www.google.com/";
String addr2 = "http://www.uprm.edu/";
String addr3 = "http://www.hotmail.com/";
//Graphical application that displays a frame window with a WELCOME.
JFrame window = new JFrame();
JLabel windowIcon = new JLabel(new ImageIcon("ComputerIcon.gif"));
JLabel windowText = new JLabel(" WELCOME TO THE PAGE-TESTER PROGRAM ");
JPanel panel= new JPanel();
panel.add(windowIcon);
panel.add(windowText);
window.setContentPane(panel);
window.pack();
window.show();
//Three correct addresses
System.out.println("* EXAMPLES OF CORRECT PAGES WITH CORRECT SERVERS *");
System.out.println();
System.out.println(addr1);
callsWebClient(addr1,address);
System.out.println(addr2);
callsWebClient(addr2,address);
System.out.println(addr3);
callsWebClient(addr3,address);
//Three incorrect addresses
System.out.println();
System.out.println("* EXAMPLES OF INCORRECT PAGES WITH CORRECT SERVERS *");
System.out.println();
System.out.println(addr1+"dfdcss");
callsWebClient(addr1+"dfdcss",address);
System.out.println(addr2+"dfdcss");
callsWebClient(addr2+"dfdcss",address);
System.out.println(addr3+"dfdcss");
callsWebClient(addr3+"dfdcss",address);
System.out.println();
System.out.println("----------------------------------------------------------------------------------------");
System.out.println(" ENTER A PAGE THAT YOU WOULD LIKE TO TEST WHETHER IT WORKS OR NOT");
System.out.println("----------------------------------------------------------------------------------------");
System.out.println();
System.out.println(" * PLEASE MAKE SURE TO FOLLOW THE FOLLOWING DESCRIPTION:
http://ADDRESS_GOES_HERE *");
System.out.println(" ** NOTE: THE SERVER MUST BE CORRECT BUT THE PAGE INCORRECT OR I WILL THROW AN **");
System.out.println(" *** EXCEPTION ***");
//Reads a line of input and stores it in "input". Calls the callsWebClient method.
BufferedReader console=new BufferedReader(new InputStreamReader(System.in));
String input=console.readLine();
callsWebClient(input,address);
}
/**
* Prints the the response given from the server.
* Calls the getResponse and setURL methods from WebClient.java.
* It will be called from main method using a single line.
*
* @param addr String received from main that contains the address.
* @param address Needed to call the WebClient.java methods.
* @throws MalformedURLException
*/
public static void callsWebClient(String addr,WebClient address) throws MalformedURLException
{
address.setURL(addr);
System.out.println(address.getResponse());
System.out.println();
}
}
Bookmarks