// File: IO26.java (Module 13) // // Author: Rahul Simha // Created: December 7, 1998 // // Using the AppletContext. import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; public class IO26 extends Applet { TextField tf; // A textfield for the URL. AppletContext context; // The applet context variable. public void init () { // We will place the text field inside a colored box. this.setBackground (Color.pink); // Create a 20-column text field. tf = new TextField (20); tf.setForeground (Color.blue); tf.addActionListener ( new ActionListener () { public void actionPerformed (ActionEvent a) { // This method is written below. display_URL (tf.getText()); } } ); this.add (tf); this.setVisible (true); // Get the applet context ready. context = this.getAppletContext(); } void display_URL (String s) { try { // Parse the URL. URL u = new URL (s); // Fetch and display in the second frame. context.showDocument (u, "part2"); } catch (MalformedURLException e) { System.out.println (e); } } }