// Simple Internet Explorer controller. // Can be used to make an instance of Internet Explorer // do simple navigation to various URLs. import iexplorer.InternetExplorer; import iexplorer.IWebBrowserApp; import java.io.BufferedReader; import java.io.InputStreamReader; public class SimpleController { public static void main(String args[]) { IWebBrowserApp app = null; try { // Instantiate an InternetExplorer InternetExplorer ie = new InternetExplorer(); // Get IWebBrowserApp app = ie.getIWebBrowserApp(); // Make the browser visible app.setVisible( true ); // If IE is trying to load any default pages, stop it. app.Stop(); System.out.println( "Page loading stopped successfully" ); // Get a buffered reader to read user input. BufferedReader in = new BufferedReader( new InputStreamReader( System.in )); for (;;) { System.out.print( "Enter command: \"load\", \"title\", \"url\" or \"quit\"> " ); String cmd = in.readLine().trim(); if ( cmd.equalsIgnoreCase( "load" )) { // Load URL System.out.print( "Enter URL> " ); String line = in.readLine(); if ( ! line.equals( "" )) { // Tell browser to load the URL app.Navigate( line ); } } else if ( cmd.equalsIgnoreCase( "title" )) { System.out.println( "Location title is " + app.getLocationName()); } else if ( cmd.equalsIgnoreCase( "url" )) { System.out.println( "Location URL is " + app.getLocationURL()); } else if ( cmd.equalsIgnoreCase( "quit" )) { break; } else if ( ! cmd.equals( "" )) System.out.println( "Unknown command \"" + cmd + "\"" ); } } catch (Exception ex) { ex.printStackTrace(); } finally { if ( app != null ) try { // If Internet Explorer has been initialized, cause it to exit. app.Quit(); } catch (Exception ex) { } try { // Shut down the COM connection. // Note: EZ JCom operations cannot be performed once JComShutdown // has been called! ezjcom.JComObject.JComShutdown(); } catch (Exception ex) { } } } }