import java.net.*; import java.io.*; import java.awt.*; import java.awt.image.*; public class ImageSizer extends Frame { TextField theURL; TextArea theOutput; Button getURL; public static void main(String[] args) { ImageSizer is = new ImageSizer(); is.resize(300, 200); is.show(); } public ImageSizer() { setLayout(new BorderLayout()); theURL = new TextField(40); add("North", theURL); theOutput = new TextArea(80, 40); add("Center", theOutput); add("South", new Button("Get URL")); } public boolean action(Event e, Object o) { if (e.target instanceof Button) { fixThePage(theURL.getText()); return true; } return false; } public void fixThePage(String thePage) { String thisLine; URL root; if (thePage != null) { //Open the URL for reading try { if (thePage.indexOf(":") != -1) { root = new URL(thePage); } else { root = new URL("http://" + thePage); } sizeAPage(root); } catch (MalformedURLException e) { System.err.println(thePage + " is not a parseable URL"); System.err.println(e); } } // end if } // end main public void sizeAPage(URL u) { char thisChar; String theTag; try { DataInputStream theHTML = new DataInputStream(u.openStream()); try { while (true) { thisChar = (char) theHTML.readByte(); if (thisChar == '<') { theTag = readTag(theHTML); if (theTag.startsWith(""); newTag = tag.substring(0,last); if (!hasWidthTag) { while (thePicture.getWidth(this) == -1) { try { Thread.currentThread().sleep(100); } catch (InterruptedException e) { } } newTag = newTag + " width=" + thePicture.getWidth(this); } if (!hasHeightTag) { while (thePicture.getHeight(this) == -1) { try { Thread.currentThread().sleep(100); } catch (InterruptedException e) { } } newTag = newTag + " height=" + thePicture.getHeight(this); } newTag = newTag + ">"; } catch (MalformedURLException e) { newTag = tag; } return newTag; } } // For this applet you don't need to // download an entire Image, just enough to get the height and width public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { if ((infoflags & ImageObserver.HEIGHT) == ImageObserver.HEIGHT && (infoflags & ImageObserver.WIDTH) == ImageObserver.WIDTH) { return false; } else { return true; } } }