|
|
|
|
|
|
|
|
|
|
|
|
|
|
 |
|
|
|
|
|
|
|
|
|
|
Java Coding Part Three: Adding Objects
Thus far our code is pretty inflexible, and it really only returns text from a single site that is hard coded. The first step in addressing this problem is to create objects to contain proxy data and site information data, which we will tie in later with an XML preferences file.
Site Object
|
import java.io.*;
public class SiteObject extends Object {
public String URL;
public String username;
public String password;
// c o n s t r u c t o r
public SiteObject(String theSite, String thePort, String user, String pass) {
super();
this.URL=theSite;
this.username=user;
this.password=pass;
} // end constructor
// no-argument constructor
public SiteObject() {
super();
this.URL=null;
this.username=null;
this.password=null;
} // end constructor
} // class |
Proxy Object
|
import java.io.*;
public class ProxyObject extends Object {
public String ProxyServer; // Proxy Server name or IP
public String ProxyPort; // Port number
public String username;
public String password;
// c o n s t r u c t o r
public ProxyObject(String theServer, String thePort, String user, String pass) {
super();
this.ProxyServer=theServer;
this.ProxyPort=thePort;
this.username=user;
this.password=pass;
} // end constructor
// no-argument constructor
public ProxyObject() {
super();
this.ProxyServer=null;
this.ProxyPort=null;
this.username=null;
this.password=null;
} // end constructor
} // class |
Now we have objects that we can use to store information about sites and the proxy server. C++ programmers will recognize these class declarations, although they might fidget at the idea of a constructor without a corresponding destructor. Fortunately, Java has good garbage collection and will take care of that for us.
Previous Section Next Section
|
|
|
|
|
 |
|
|
|
|
|
|
 |
|
|
|
|
|
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
 |
|
|
|
|
|
|
|
Site by Warner Technology Consulting. All material is copyright 1999. If you reference material on this site, you are expected to annotate the source from which it came. That is, you may use information on this site, but you must clearly state from where you obtained it. |
|
|
|
|
Page last updated on Thu, Dec 23, 1999 |
|
|
|