package class9_2_VirtualProxy_start; import javax.swing.*; import java.awt.*; import java.io.IOException; import java.net.URL; /** * A basic image viewing application * @author hornick */ public class ImageViewer extends JFrame { // 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"); setSize(2048,1400); Icon icon = null; try { // Pictures that take a LONG time to load: // http://earthobservatory.nasa.gov/Features/NightLights/page3.php // http://eoimages.gsfc.nasa.gov/images/imagerecords/79000/79765/dnb_land_ocean_ice.2012.13500x6750.jpg -- sometimes loads on campus // http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73580/world.topo.bathy.200401.3x21600x21600.C2.jpg -- fails to load from home machine // http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73580/world.topo.bathy.200401.3x21600x10800.jpg -- also fails to load // https://www.google.com/search?q=very+high+resolution+image+earth&source=lnms&tbm=isch&sa=X&ved=0ahUKEwid0cGXkYDLAhVhmoMKHR72B54Q_AUIBygB&biw=1270&bih=865#q=very+high+resolution+image+earth&tbm=isch&tbs=isz:lt,islt:70mp&imgrc=8jYzHBBfu11rKM%3A // URL url = new URL("http://assets.overclock.net.s3.amazonaws.com/f/f7/f740be93_vbattach181511.jpeg"); // URL url = new URL("http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73580/world.topo.bathy.200401.3x21600x10800.jpg"); URL url = new URL("http://eoimages.gsfc.nasa.gov/images/imagerecords/79000/79765/dnb_land_ocean_ice.2012.13500x6750.jpg"); // icon = new ImageProxy(url,this); icon = new ImageIcon(url); } catch (IOException e) { e.printStackTrace(); //TODO: change body of catch statement use File | Settings | File Templates. } // setSize(icon.getIconWidth() + 800,icon.getIconHeight() + 100); // set the window size imageComponent = new ImageComponent(icon); // add the icon to the canvas System.out.println("Scroll pane added"); JPanel imageHolder = new JPanel(new BorderLayout()); imageHolder.add(imageComponent,BorderLayout.CENTER); imageHolder.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); JScrollPane pictureScrollPane = new JScrollPane(imageHolder,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); add(pictureScrollPane); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } }