package start9_3_VirtualProxy; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import java.net.URL; /** * A basic image viewing application * @author hornick */ public class ImageViewer extends JFrame { /** * Where to find resources */ public static final String baseDir = "src/example9_3_Proxy.virtualProxy/"; // a UI component that contains the image private ImageComponent imageComponent; public static void main(String[] args){ ImageViewer iv = new ImageViewer(); iv.initUI(); } // init the UI for this app private void initUI() { setTitle("Image Viewer"); Icon icon = null; try { System.out.println("Debug: starting to load remote image"); Thread.sleep(3000); // simulate a long load time // the following may take some time to execute // if the imageURL is on a slow remote server URL url = new URL("http://assets.overclock.net.s3.amazonaws.com/f/f7/f740be93_vbattach181511.jpeg"); icon = new ImageIcon(url); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(0); } setSize(icon.getIconWidth() + 800,icon.getIconHeight() + 100); // set the window size imageComponent = new ImageComponent(icon); // add the icon to the canvas getContentPane().add(imageComponent); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } }