import com.ms.xml.parser.ParseException; import com.ms.xml.om.Document; import java.awt.*; import java.net.*; import java.applet.Applet; public class showtextwin extends Applet { Label label1; TextField text1; Button button1; String xmlfile = "showtextwin.xml"; StringBuffer xmlurl; // Uncomment the following to use this in a Java application // public static void main (String args[]) { // showtextwinFrame frame = new showtextwinFrame("The showtextwin app"); // frame.resize(450,300); // showtextwin applet = new showtextwin(); // frame.add("Center", applet); // applet.init(); // applet.start(); // frame.show(); // } public void init(){ String base = getDocumentBase().toString(); StringBuffer basebuf = new StringBuffer(base); xmlurl = new StringBuffer(xmlfile); int idx = basebuf.toString().lastIndexOf('/'); basebuf.setLength(idx+1); if (basebuf != null) { xmlurl.insert(0, basebuf.toString()); } this.resize(500,100); label1 = new Label(xmlurl.toString()); add(label1); text1 = new TextField(60); add(text1); button1 = new Button("Get the XML text"); add(button1); } public boolean action (Event e, Object o) { if (e.target.equals(button1)) { URL url = null; try { url = new URL(xmlurl.toString()); } catch (SecurityException e1) { // (MalformedURLException e1) { label1.setText("Security exception on url for " + xmlurl); } catch (MalformedURLException e1) { label1.setText("Cannot create URL for " + xmlurl); } Document d = new Document(); try { d.load(url); } catch (ParseException e2) { d.reportError(e2, System.out); //label1.setText("Parse Exception"); } catch (SecurityException e1) { // (MalformedURLException e1) { label1.setText("Security exception on load for " + xmlurl); } catch (NullPointerException e1) { label1.setText("Null pointer exception on load for " + xmlurl); } if (d != null) { text1.setText(d.getText()); } } return true; } } // class showtextwinFrame extends Frame // { // public showtextwinFrame(String str) // { // super(str); // } // public boolean handleEvent(Event evt) // { // switch (evt.id) // { // case Event.WINDOW_DESTROY: // dispose(); // System.exit(0); // return true; // default: // return super.handleEvent(evt); // } // } // }