JDIC API V2006 Release 0308

org.jdesktop.jdic.browser
类 WebBrowser

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Canvas
          继承者 org.jdesktop.jdic.browser.WebBrowser
所有已实现的接口:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, IWebBrowser

public class WebBrowser
extends java.awt.Canvas
implements IWebBrowser

A WebBrowser component represents a blank rectangular area of the screen onto which the application can load webpages or from which the application can trap events from the browser window. In order to show WebBrowser component in GUI, users need to add WebBrowser to a top-level container, such as Frame.

The class that is interested in processing a WebBrowser event should implement interface WebBrowserListener, and the object created with that class should use WebBrowser's addWebBrowserListener method to register as a listener.

As an AWT component, a WebBrowser component must be hosted by a native container somewhere higher up in the component tree (for example, by a JPanel object).

另请参见:
WebBrowserEvent, WebBrowserListener, 序列化表格

嵌套类摘要
 
从类 java.awt.Canvas 继承的嵌套类/接口
java.awt.Canvas.AccessibleAWTCanvas
 
从类 java.awt.Component 继承的嵌套类/接口
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
字段摘要
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造函数摘要
WebBrowser()
          Constructs a new WebBrowser object with no URL specified.
WebBrowser(boolean autoDispose)
          Constructs a new WebBrowser object with the specified boolean value autoDispose as the flag which indicates whether this instance will automatically dispose itself in removeNotify() or should be disposed by the developer directly calling dispose().
WebBrowser(java.net.URL url)
          Constructs a new WebBrowser with an URL specified.
WebBrowser(java.net.URL url, boolean autoDispose)
          Constructs a new WebBrowser with an specified URL and boolean flag to indicate the dispose schema.
 
方法摘要
 void addNotify()
          Creates the peer for this WebBrowser component.
 void addWebBrowserListener(WebBrowserListener listener)
          Adds a WebBrowserEvent listener to the listener list.
 java.awt.Component asComponent()
          Returns the component to which the Browser paints.
 void back()
          Navigates backward one item in the history list.
 void dispatchWebBrowserEvent(WebBrowserEvent e)
           
 void dispose()
          Release this instance's resource and make it undisplayable.
 java.lang.String executeScript(java.lang.String javaScript)
          Executes the specified JavaScript code on the currently loaded document.
 void forward()
          Navigates forward one item in the history list.
static java.lang.String getBrowserBinary()
          已过时。 As of release 0.9 of JDIC. This method was unnecessarily exposed and will be removed in a future release.
 IBrowserEngine getBrowserEngine()
          The BrowserEngine that was responsible for creating the browser instance.
 java.lang.String getContent()
          Returns the HTML content of a document, loaded in a browser.
 java.lang.String getInitFailureMessage()
           
 int getInstanceNum()
          A IWebBrowser must have a ticket to identify itself, here is the instance num.For a IWebBrowser instance, a native browser instance will be created to deal with its requests, this instance num will be used get according native browser instance.
 int getNativeWindow()
          Get the windows' handler of native window
 java.net.URL getURL()
          Returns the URL of the resource that is currently being loaded.
 WebBrowserListener[] getWebBrowserListeners()
          Returns an array of all the registered WebBrowser listeners.
 boolean isAutoDispose()
          Return the boolean flag which indicates how to dispose this instance.
 boolean isBackEnabled()
          Checks whether this WebBrowser object's back command is enabled.
 boolean isForwardEnabled()
          Checks whether this WebBrowser object's forward command is enabled.
 boolean isInitialized()
          Checks whether this WebBrowser object is initialized successfully.
 boolean isSynchronize()
          If the webbrowser works under synchronize model
 void paint(java.awt.Graphics g)
          Could only get HWND when this method is called.This will fix the can't get awt HWND error.
 void print()
          Prints the currently loaded document.
 void refresh()
          Reloads the URL that is currently loaded in the WebBrowser component.
 void removeNotify()
          Makes this WebBrowser component undisplayable by destroying it native screen resource if the isAutoDispose() return true.
 void removeWebBrowserListener(WebBrowserListener listener)
          Removes a WebBrowserEvent listener from the listener list.
 void setBounds(int x, int y, int width, int height)
          Moves and resizes this component.
 void setContent(java.lang.String htmlContent)
          Sets new HTML content.
static void setDebug(boolean b)
          Enables or disables debug message output.
 void setInitFailureMessage(java.lang.String msg)
           
 void setInitialized(boolean b)
          Set if the IWebBrowser has been initialized.
 void setURL()
          Sets the loaded page to be a blank page.
 void setURL(java.net.URL url)
          Navigates to a resource identified by a URL.
 void setURL(java.net.URL url, java.lang.String postData)
          Navigates to a resource identified by a URL, with the HTTP POST data to send to the server.
 void setURL(java.net.URL url, java.lang.String postData, java.lang.String headers)
          Navigates to a resource identified by a URL, with the HTTP POST data and HTTP headers to send to the server.
 void stop()
          Stops any page loading and rendering activities.
 void syncSetURL(java.net.URL url)
          Synchronously navigates to a resource identified by a URL.
 void syncSetURL(java.net.URL url, java.lang.String postData)
          Synchronously navigates to a resource identified by a URL, with the HTTP POST data to send to the server.
 void syncSetURL(java.net.URL url, java.lang.String postData, java.lang.String headers)
          Synchronously navigates to a resource identified by a URL, with the HTTP POST data and HTTP headers to send to the server.
protected  boolean willOpenURL(java.net.URL url)
          Called before a navigation occurs.
protected  boolean willOpenWindow(java.net.URL url)
          Called when a new window is to be created for loading a resource.
 
从类 java.awt.Canvas 继承的方法
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
从类 java.awt.Component 继承的方法
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

构造函数详细信息

WebBrowser

public WebBrowser()
Constructs a new WebBrowser object with no URL specified. This instance will automatically dispose itself when removeNotify() is called.

This constructor is equivalent to WebBrowser(true).

另请参见:
WebBrowser(boolean), removeNotify(), dispose()

WebBrowser

public WebBrowser(boolean autoDispose)
Constructs a new WebBrowser object with the specified boolean value autoDispose as the flag which indicates whether this instance will automatically dispose itself in removeNotify() or should be disposed by the developer directly calling dispose().

This constructor is equivalent to WebBrowser(null, autoDispose) .

参数:
autoDispose - ture to indicate this instance will automatically dispose itself in removeNotify(); false to indicate the developer should call dispose() when this instance is no longer needed.
另请参见:
removeNotify(), dispose(), isAutoDispose()

WebBrowser

public WebBrowser(java.net.URL url)
Constructs a new WebBrowser with an URL specified. This instance will automatically dispose itself when removeNotify() is called.

This constructor is equivalent to WebBrowser(url, true).

参数:
url - the URL to be shown in this instance.
另请参见:
WebBrowser(boolean), removeNotify(), dispose()

WebBrowser

public WebBrowser(java.net.URL url,
                  boolean autoDispose)
Constructs a new WebBrowser with an specified URL and boolean flag to indicate the dispose schema.

参数:
url - the URL to be shown in this instance.
autoDispose - ture to indicate this instance will automatically dispose itself in removeNotify(); false to indicate the developer should call dispose() when this instance is no longer needed.
另请参见:
removeNotify(), dispose(), isAutoDispose()
方法详细信息

setInitialized

public void setInitialized(boolean b)
从接口 IWebBrowser 复制的描述
Set if the IWebBrowser has been initialized.

指定者:
接口 IWebBrowser 中的 setInitialized

setInitFailureMessage

public void setInitFailureMessage(java.lang.String msg)
指定者:
接口 IWebBrowser 中的 setInitFailureMessage

paint

public void paint(java.awt.Graphics g)
Could only get HWND when this method is called.This will fix the can't get awt HWND error.

覆盖:
java.awt.Canvas 中的 paint

addNotify

public void addNotify()
Creates the peer for this WebBrowser component. The peer allows us to modify the appearance of the WebBrowser component without changing its functionality.

覆盖:
java.awt.Canvas 中的 addNotify
另请参见:
removeNotify()

removeNotify

public void removeNotify()
Makes this WebBrowser component undisplayable by destroying it native screen resource if the isAutoDispose() return true. Or just make this instance invisible if the isAutoDispose() return false.

This method is called by the toolkit internally and should not be called directly by programs.

If isAutoDispose() return false, developer should call dispose() when this instance is no longer needed. Otherwise, it resource will never be released untill this JVM exit.

覆盖:
java.awt.Component 中的 removeNotify
另请参见:
addNotify(), dispose(), isAutoDispose()

dispose

public void dispose()
Release this instance's resource and make it undisplayable. If isAutoDispose() return true, this method will be called by the toolkit internally. If isAutoDispose() return false, this method should be called by developer when this instance is no longer needed.

另请参见:
removeNotify(), isAutoDispose()

isAutoDispose

public boolean isAutoDispose()
Return the boolean flag which indicates how to dispose this instance.

返回:
true if this instance should be disposed by itself when removeNotify() is called. false if this instance should be disposed by the developer directly calling dispose() when it is no longer needed.
另请参见:
removeNotify(), addNotify(), dispose()

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.

覆盖:
java.awt.Component 中的 setBounds
参数:
x - - the new x-coordinate of this component
y - - the new y-coordinate of this component
width - - the new width of this component
height - - the new height of this component

dispatchWebBrowserEvent

public void dispatchWebBrowserEvent(WebBrowserEvent e)
指定者:
接口 IWebBrowser 中的 dispatchWebBrowserEvent

addWebBrowserListener

public void addWebBrowserListener(WebBrowserListener listener)
Adds a WebBrowserEvent listener to the listener list. If listener is null, no exception is thrown and no action is performed.

指定者:
接口 IWebBrowser 中的 addWebBrowserListener
参数:
listener - the WebBrowser event listener.

removeWebBrowserListener

public void removeWebBrowserListener(WebBrowserListener listener)
Removes a WebBrowserEvent listener from the listener list. If listener is null, no exception is thrown and no action is performed. If the listener is not in the listener list, no listener is removed.

指定者:
接口 IWebBrowser 中的 removeWebBrowserListener
参数:
listener - the WebBrowser event listener.

getWebBrowserListeners

public WebBrowserListener[] getWebBrowserListeners()
Returns an array of all the registered WebBrowser listeners.

返回:
all of this component's WebBrowserListener s or an empty array if no component listeners are currently registered.
自从:
0.9

getURL

public java.net.URL getURL()
Returns the URL of the resource that is currently being loaded.

指定者:
接口 IWebBrowser 中的 getURL
返回:
the current URL being loaded, or null if no URL is currentlloadayed or the WebBrowser is not yet initialized.

setURL

public void setURL()
Sets the loaded page to be a blank page.

指定者:
接口 IWebBrowser 中的 setURL

setURL

public void setURL(java.net.URL url)
Navigates to a resource identified by a URL.

指定者:
接口 IWebBrowser 中的 setURL
参数:
url - the URL to navigate to.

setURL

public void setURL(java.net.URL url,
                   java.lang.String postData)
Navigates to a resource identified by a URL, with the HTTP POST data to send to the server.

指定者:
接口 IWebBrowser 中的 setURL
参数:
url - the URL to navigate to.
postData - the post data to send with the HTTP POST transaction. For example, "username=myid&password=mypasswd"

setURL

public void setURL(java.net.URL url,
                   java.lang.String postData,
                   java.lang.String headers)
Navigates to a resource identified by a URL, with the HTTP POST data and HTTP headers to send to the server.

参数:
url - the URL to navigate to.
postData - the post data to send with the HTTP POST transaction. For example, "username=myid&password=mypasswd"
headers - the HTTP headers to send with the HTTP POST transaction.
自从:
0.9.2

syncSetURL

public void syncSetURL(java.net.URL url)
                throws JdicInitException
Synchronously navigates to a resource identified by a URL.

参数:
url - the URL to navigate to.
抛出:
JdicInitException
自从:
0.9.2

syncSetURL

public void syncSetURL(java.net.URL url,
                       java.lang.String postData)
                throws JdicInitException
Synchronously navigates to a resource identified by a URL, with the HTTP POST data to send to the server.

参数:
url - the URL to navigate to.
postData - the post data to send with the HTTP POST transaction. For example, "username=myid&password=mypasswd"
抛出:
JdicInitException

syncSetURL

public void syncSetURL(java.net.URL url,
                       java.lang.String postData,
                       java.lang.String headers)
                throws JdicInitException
Synchronously navigates to a resource identified by a URL, with the HTTP POST data and HTTP headers to send to the server.

参数:
url - the URL to navigate to.
postData - the post data to send with the HTTP POST transaction. For example, "username=myid&password=mypasswd"
headers - the HTTP headers to send with the HTTP POST transaction.
抛出:
JdicInitException
自从:
0.9.2

back

public void back()
Navigates backward one item in the history list.

指定者:
接口 IWebBrowser 中的 back

forward

public void forward()
Navigates forward one item in the history list.

指定者:
接口 IWebBrowser 中的 forward

refresh

public void refresh()
Reloads the URL that is currently loaded in the WebBrowser component.

指定者:
接口 IWebBrowser 中的 refresh

stop

public void stop()
Stops any page loading and rendering activities.

指定者:
接口 IWebBrowser 中的 stop

print

public void print()
Prints the currently loaded document.

This is a convenience method to use executeScript to print the currently loaded document:

 
  
        
    WebBrowser webBrowser = new WebBrowser();
           ......
    webBrowser.executeScript("window.print();");        
    
   
  
 

自从:
0.9.2
另请参见:
executeScript(java.lang.String)

setContent

public void setContent(java.lang.String htmlContent)
Sets new HTML content.

指定者:
接口 IWebBrowser 中的 setContent
参数:
htmlContent - the HTML content to set.
自从:
0.9

getContent

public java.lang.String getContent()
Returns the HTML content of a document, loaded in a browser.

指定者:
接口 IWebBrowser 中的 getContent
返回:
the HTML content of a document, loaded in a browser.
自从:
0.9

executeScript

public java.lang.String executeScript(java.lang.String javaScript)
Executes the specified JavaScript code on the currently loaded document. This should not be called until after a documentCompleted event fired in WebBrowserListener.

For example, execute JavaScript to show an alert dialog:

 
 
 // Show a JavaScript alert dialog.    
 WebBrowser webBrowser = new WebBrowser();
 webBrowser.executeScript("alert('Using executeScript')");
 

指定者:
接口 IWebBrowser 中的 executeScript
返回:
the result of JavaScript execution, if there is any.
自从:
0.9
另请参见:
WebBrowserListener.documentCompleted(org.jdesktop.jdic.browser.WebBrowserEvent)

setDebug

public static void setDebug(boolean b)
Enables or disables debug message output. Debug message out is disabled initially by default. Calls it via reflection when necessary.

参数:
b - if true, debug message output is enabled; otherwise debug message output is disabled.

getBrowserBinary

public static java.lang.String getBrowserBinary()
已过时。 As of release 0.9 of JDIC. This method was unnecessarily exposed and will be removed in a future release.

Returns the name of the embedded browser's native binary, which runs as a standalone native process.


isInitialized

public boolean isInitialized()
Checks whether this WebBrowser object is initialized successfully.

指定者:
接口 IWebBrowser 中的 isInitialized
返回:
true if the WebBrowser object is initialized successfully; otherwise, false.

isBackEnabled

public boolean isBackEnabled()
Checks whether this WebBrowser object's back command is enabled.

指定者:
接口 IWebBrowser 中的 isBackEnabled
返回:
true if the WebBrowser can navigate to the previous session history item, and false otherwise.
另请参见:
back()

isForwardEnabled

public boolean isForwardEnabled()
Checks whether this WebBrowser object's forward command is enabled.

指定者:
接口 IWebBrowser 中的 isForwardEnabled
返回:
true if the WebBrowser can navigate to the next session history item, and false otherwise.
另请参见:
forward()

willOpenURL

protected boolean willOpenURL(java.net.URL url)
Called before a navigation occurs.

A subclass can override this method to block the navigation or allow it to proceed.

参数:
url - the URL to navigate to.
返回:
false will block the navigation from starting; true otherwise. By default, it returns true.

willOpenWindow

protected boolean willOpenWindow(java.net.URL url)
Called when a new window is to be created for loading a resource.

A subclass can override this method to block the creation of a new window or allow it to proceed.

参数:
url - string value of url to be opened
返回:
false will block the creation of a new window; true otherwise. By default, it returns true.

getInstanceNum

public int getInstanceNum()
从接口 IWebBrowser 复制的描述
A IWebBrowser must have a ticket to identify itself, here is the instance num.For a IWebBrowser instance, a native browser instance will be created to deal with its requests, this instance num will be used get according native browser instance.

指定者:
接口 IWebBrowser 中的 getInstanceNum
返回:

getNativeWindow

public int getNativeWindow()
从接口 IWebBrowser 复制的描述
Get the windows' handler of native window

指定者:
接口 IWebBrowser 中的 getNativeWindow
返回:

asComponent

public java.awt.Component asComponent()
从接口 IWebBrowser 复制的描述
Returns the component to which the Browser paints. This method is needed to add a Browser to

指定者:
接口 IWebBrowser 中的 asComponent
返回:
The component on which the Browser paints.

getBrowserEngine

public IBrowserEngine getBrowserEngine()
从接口 IWebBrowser 复制的描述
The BrowserEngine that was responsible for creating the browser instance. Use the BrowserEngine to get information about the Embedded Browser Component that is used for browsing.

指定者:
接口 IWebBrowser 中的 getBrowserEngine
返回:
The BrowserEngine that was responsible for creating this browser instance.

getInitFailureMessage

public java.lang.String getInitFailureMessage()
指定者:
接口 IWebBrowser 中的 getInitFailureMessage

isSynchronize

public boolean isSynchronize()
从接口 IWebBrowser 复制的描述
If the webbrowser works under synchronize model

指定者:
接口 IWebBrowser 中的 isSynchronize
返回:
Returns the synchronize.

JDIC API V2006 Release 0308

For more information and documentation on JDIC, see JDIC website.

That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, working code examples, license terms and bug report information.

Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.