// File: TestAwt14.java (Module 9) // // Author: Rahul Simha // Created: October 13, 1998 // // Images - from a URL. import java.awt.*; import java.net.*; // For class URL. class NewFrame extends Frame { // Constructor. public NewFrame (int width, int height) { // Set the title and other frame parameters. this.setTitle ("Gif image"); this.setResizable (true); this.setBackground (Color.cyan); this.setSize (width, height); // Show the frame. this.setVisible (true); } // Override paint(): public void paint (Graphics g) { Toolkit tk = Toolkit.getDefaultToolkit (); // try-catch needed since URL constructor throws an exception. try { // URL is in java.net. URL u = new URL ("http://www.seas.gwu.edu/~simha/canyon.jpeg"); // Load the image using the second form of getImage(). Image img = tk.getImage (u); // Display image. g.drawImage (img, 0, 0, this); } catch (MalformedURLException e) { System.out.println (e); } } // "paint" } // End of class "NewFrame" public class TestAwt14 { public static void main (String[] argv) { NewFrame nf = new NewFrame (600, 300); } }