Methods Summary |
---|
public boolean | action(java.awt.Event e, java.lang.Object o)
if (e.target instanceof Button) {
fetchURL(url.getText());
return true;
}
else if (e.target == url) {
fetchURL(url.getText());
return true;
}
else {
return false;
}
|
public void | fetchURL(java.lang.String s)
try {
URL u = new URL(s);
try {
Object o = u.getContent();
if (o instanceof InputStream) {
showText((InputStream) o);
}
else {
showText(o.toString());
}
}
catch (IOException e) {
showText("Could not connect to " + u.getHost());
}
catch (NullPointerException e) {
showText("There was a problem with the content");
}
}
catch (MalformedURLException e) {
showText(url.getText() + " is not a valid URL");
}
|
public void | init()
textDisplay = new TextArea();
add("Center", textDisplay);
// We don't want the buttons and fields in the north and south
// to fill their respertive sections so we'll add Panels there
// and use FlowLayout's in the Panels
Panel SouthPanel = new Panel();
Panel NorthPanel = new Panel();
NorthPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
SouthPanel.add(new Button("Get URL"));
NorthPanel.add("North", new Label("URL: "));
url = new TextField(40);
NorthPanel.add("North", url);
add("South", SouthPanel);
add("North", NorthPanel);
|
public static void | main(java.lang.String[] args)
URLRequestor a = new URLRequestor();
a.show();
|
void | showText(java.lang.String s)
textDisplay.setText(s);
|
void | showText(java.io.InputStream is)
String nextline;
textDisplay.setText("");
try {
DataInputStream dis = new DataInputStream(is);
while((nextline = dis.readLine()) != null) {
textDisplay.appendText(nextline + "\n");
}
}
catch (IOException e) {
textDisplay.appendText(e.toString());
}
|