Noramlly, more than two way you can use a web browser with your Java programm.
1.Fire commands to invoke a web browser with Java runtime support.
// cmd = ‘rundll32 url.dll,FileProtocolHandler http://…’
cmd = WIN_PATH + ” ” + WIN_FLAG + ” ” + url;
Process p = Runtime.getRuntime().exec(cmd);
See the API Spec of Java for Process, and Java Tip 66 of the Resources section for more information.
2. Use a wrapped browser control
2.1 Use Jacob, the open source COM wrapper. e.g.,
protected void openIExplorer(){
comp = new ActiveXComponent( “InternetExplorer.Application” );
comp.setProperty( “Visible”, new Variant(true) );
comp.invoke( “Navigate”, new Variant[]{ new Variant((String)comboFilename.getSelectedItem()) } );
2.2 Use browser wrapper provided by SWT.
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.CloseWindowListener;
import org.eclipse.swt.browser.LocationAdapter;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.OpenWindowListener;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.browser.StatusTextEvent;
import org.eclipse.swt.browser.StatusTextListener;
import org.eclipse.swt.browser.VisibilityWindowAdapter;
import org.eclipse.swt.browser.WindowEvent;
3. or any other ways I havn’t figured out…
Resources:
- Java Tip 66: Control browsers from your Java application
- JavaTM 2 Platform Standard Edition 5.0 API Specification
- The JACOB Project: A JAva-COM Bridge
- SWT Browser
- Package org.eclipse.swt.browser
- Developer Forums java to invoke IExplore?
Technorati : firefox, ie, java, linux, netscape, safri, web browser, windows
Del.icio.us : firefox, ie, java, linux, netscape, safri, web browser, windows

No comments:
Post a Comment