精华内容
下载资源
问答
  • java程序关闭当前页面

    2020-05-14 21:06:25
    重新创建的状态Window及其子组件将等同于这些对象在其中的点的状态Window被布置(不考虑这些操作之间附加的修改)。 注意 :当Java虚拟机(VM)中的最后一个可显示的窗口被丢弃时,VM可能会终止。

    public void dispose()释放此Window ,其子组件及其所有子集所使用的所有本地屏幕资源。 也就是说,这些Component的资源将被销毁,它们消耗的任何内存将被返回到操作系统,并且它们将被标记为不可显示。
    Window及其子组件可以通过重新生成本地资源,随后调用pack或show 。 重新创建的状态Window及其子组件将等同于这些对象在其中的点的状态Window被布置(不考虑这些操作之间附加的修改)。

    注意 :当Java虚拟机(VM)中的最后一个可显示的窗口被丢弃时,VM可能会终止。 见AWT Threading Issues以获取更多信息。

    展开全文
  • 我在使用时用到两个,getText()和setUrl(String url, String post_data),分别取得当前打开页面的原代码和采用post方式打开页面。现在修改Browser类如下:/********************************************************...

    在swt提供的browser 类中间,缺少不少有用的方法。我在使用时用到两个,getText()和setUrl(String url, String post_data),分别取得当前打开页面的原代码和采用post方式打开页面。现在修改Browser类如下:

    /*******************************************************************************

    * Copyright (c) 2003, 2005 IBM Corporation and others.

    * All rights reserved. This program and the accompanying materials

    * are made available under the terms of the Eclipse Public License v1.0

    * which accompanies this distribution, and is available at

    * http://www.eclipse.org/legal/epl-v10.html

    *

    * Contributors:

    *     IBM Corporation - initial API and implementation

    *******************************************************************************/

    package com.***.browser;

    import java.text.Collator;

    import java.util.Locale;

    import org.eclipse.swt.*;

    import org.eclipse.swt.graphics.*;

    import org.eclipse.swt.internal.ole.win32.*;

    import org.eclipse.swt.internal.win32.*;

    import org.eclipse.swt.ole.win32.*;

    import org.eclipse.swt.widgets.*;

    /**

    * Instances of this class implement the browser user interface metaphor. It

    * allows the user to visualize and navigate through HTML documents.

    *

    * Note that although this class is a subclass of Composite, it

    * does not make sense to set a layout on it.

    *

    *

    * IMPORTANT: This class is not intended to be subclassed.

    *

    *

    * @since 3.0

    */

    public class Browser extends Composite {

    static int CodePage = OS.GetACP();

    public static int maxBrowserId = 0;

    private int browserId = 0;

    private BrowserInfo browserInfo = null;

    OleFrame frame;

    OleControlSite site;

    OleAutomation auto;

    boolean back, forward, navigate, delaySetText;

    Point location;

    Point size;

    boolean addressBar = true, menuBar = true, statusBar = true, toolBar = true;

    int info;

    int globalDispatch;

    String _text;

    String html;

    /* External Listener management */

    CloseWindowListener[] closeWindowListeners = new CloseWindowListener[0];

    LocationListener[] locationListeners = new LocationListener[0];

    OpenWindowListener[] openWindowListeners = new OpenWindowListener[0];

    ProgressListener[] progressListeners = new ProgressListener[0];

    StatusTextListener[] statusTextListeners = new StatusTextListener[0];

    TitleListener[] titleListeners = new TitleListener[0];

    VisibilityWindowListener[] visibilityWindowListeners = new VisibilityWindowListener[0];

    static final int BeforeNavigate2 = 0xfa;

    static final int CommandStateChange = 0x69;

    static final int DocumentComplete = 0x103;

    static final int NavigateComplete2 = 0xfc;

    static final int NewWindow2 = 0xfb;

    static final int OnMenuBar = 0x100;

    static final int OnStatusBar = 0x101;

    static final int OnToolBar = 0xff;

    static final int OnVisible = 0xfe;

    static final int ProgressChange = 0x6c;

    static final int RegisterAsBrowser = 0x228;

    static final int StatusTextChange = 0x66;

    static final int TitleChange = 0x71;

    static final int WindowClosing = 0x107;

    static final int WindowSetHeight = 0x10b;

    static final int WindowSetLeft = 0x108;

    static final int WindowSetResizable = 0x106;

    static final int WindowSetTop = 0x109;

    static final int WindowSetWidth = 0x10a;

    static final short CSC_NAVIGATEFORWARD = 1;

    static final short CSC_NAVIGATEBACK = 2;

    static final int INET_E_DEFAULT_ACTION = 0x800C0011;

    static final int READYSTATE_COMPLETE = 4;

    static final int URLPOLICY_ALLOW = 0x00;

    static final int URLPOLICY_DISALLOW = 0x03;

    static final int URLZONE_LOCAL_MACHINE = 0;

    static final int URLZONE_INTRANET = 1;

    static final int URLACTION_ACTIVEX_MIN = 0x00001200;

    static final int URLACTION_ACTIVEX_MAX = 0x000013ff;

    static final int URLACTION_ACTIVEX_RUN = 0x00001200;

    static final int URLACTION_JAVA_MIN = 0x00001C00;

    static final int URLPOLICY_JAVA_LOW = 0x00030000;

    static final int URLACTION_JAVA_MAX = 0x00001Cff;

    static final int DISPID_AMBIENT_DLCONTROL = -5512;

    static final int DLCTL_DLIMAGES = 0x00000010;

    static final int DLCTL_VIDEOS = 0x00000020;

    static final int DLCTL_BGSOUNDS = 0x00000040;

    static final int DLCTL_NO_SCRIPTS = 0x00000080;

    static final int DLCTL_NO_JAVA = 0x00000100;

    static final int DLCTL_NO_RUNACTIVEXCTLS = 0x00000200;

    static final int DLCTL_NO_DLACTIVEXCTLS = 0x00000400;

    static final int DLCTL_DOWNLOADONLY = 0x00000800;

    static final int DLCTL_NO_FRAMEDOWNLOAD = 0x00001000;

    static final int DLCTL_RESYNCHRONIZE = 0x00002000;

    static final int DLCTL_PRAGMA_NO_CACHE = 0x00004000;

    static final int DLCTL_FORCEOFFLINE = 0x10000000;

    static final int DLCTL_NO_CLIENTPULL = 0x20000000;

    static final int DLCTL_SILENT = 0x40000000;

    static final int DOCHOSTUIFLAG_THEME = 0x00040000;

    static final int DOCHOSTUIFLAG_NO3DBORDER = 0x0000004;

    static final int DOCHOSTUIFLAG_NO3DOUTERBORDER = 0x00200000;

    static final String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$

    static final String URL_DIRECTOR = "http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab"; //$NON-NLS-1$

    /* Package Name */

    static final String PACKAGE_PREFIX = "com.macrosoft.browser."; //$NON-NLS-1$

    /**

    * Constructs a new instance of this class given its parent and a style

    * value describing its behavior and appearance.

    *

    * The style value is either one of the style constants defined in class

    * SWT which is applicable to instances of this class, or

    * must be built by bitwise OR'ing together (that is, using the

    * int "|" operator) two or more of those SWT

    * style constants. The class description lists the style constants that are

    * applicable to the class. Style bits are also inherited from superclasses.

    *

    *

    * @param parent

    *            a widget which will be the parent of the new instance (cannot

    *            be null)

    * @param style

    *            the style of widget to construct

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the parent is null

    *               

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS - if not called from the

    *                thread that created the parent

    *               

    * @exception SWTError

    *               

    *               

    ERROR_NO_HANDLES if a handle could not be obtained

    *                for browser creation

    *               

    *

    * @see Widget#getStyle

    *

    * @since 3.0

    */

    public Browser(Composite parent, int style) {

    super(parent, style & ~SWT.BORDER);

    this.browserId = ++maxBrowserId;

    browserInfo = new BrowserInfo(this.browserId);//BorserInfo是我自己创建的类,没有必要用

    BrowserManager.addBrowserInfo(browserInfo);// ????????browser

    info = Browser.DOCHOSTUIFLAG_THEME;

    if ((style & SWT.BORDER) == 0)

    info |= Browser.DOCHOSTUIFLAG_NO3DOUTERBORDER;

    frame = new OleFrame(this, SWT.NONE);

    try {

    site = new WebSite(frame, SWT.NONE, "Shell.Explorer"); //$NON-NLS-1$

    } catch (SWTException e) {

    dispose();

    SWT.error(SWT.ERROR_NO_HANDLES);

    }

    site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);

    auto = new OleAutomation(site);

    Listener listener = new Listener() {

    public void handleEvent(Event e) {

    switch (e.type) {

    case SWT.Dispose: {

    if (auto != null)

    auto.dispose();

    auto = null;

    break;

    }

    case SWT.Resize: {

    frame.setBounds(getClientArea());

    break;

    }

    case SWT.KeyDown:

    case SWT.KeyUp: {

    notifyListeners(e.type, e);

    break;

    }

    }

    }

    };

    addListener(SWT.Dispose, listener);

    addListener(SWT.Resize, listener);

    site.addListener(SWT.KeyDown, listener);

    site.addListener(SWT.KeyUp, listener);

    // addListener(SWT.FocusIn, new Listener() {

    // public void handleEvent(Event e) {

    // System.out.println("Browser " + browserId + " Selected");

    // }

    // });

    OleListener oleListener = new OleListener() {

    public void handleEvent(OleEvent event) {

    switch (event.type) {

    case BeforeNavigate2: {

    Variant varResult = event.arguments[1];

    String url = varResult.getString();

    LocationEvent newEvent = new LocationEvent(Browser.this);

    newEvent.display = getDisplay();

    newEvent.widget = Browser.this;

    newEvent.location = url;

    newEvent.doit = true;

    for (int i = 0; i < locationListeners.length; i++)

    locationListeners[i].changing(newEvent);

    // browserInfo.setUrl(event.arguments[1].getString());

    //开出该段代码读取请求的url和postdata

    //Variant postData = event.arguments[4];

    //if (!browserInfo.isOpenWindow()) {

    // System.out.println("URL = " + event.arguments[1].getString());

    // System.out.println("PostData = " + readSafeArray(postData));

    // browserInfo.setPostData(readSafeArray(postData));

    //}

    Variant cancel = event.arguments[6];

    if (cancel != null) {

    int pCancel = cancel.getByRef();

    COM

    .MoveMemory(pCancel,

    new short[] { newEvent.doit ? COM.VARIANT_FALSE : COM.VARIANT_TRUE }, 2);

    }

    break;

    }

    case CommandStateChange: {

    boolean enabled = false;

    Variant varResult = event.arguments[0];

    int command = varResult.getInt();

    varResult = event.arguments[1];

    enabled = varResult.getBoolean();

    switch (command) {

    case CSC_NAVIGATEBACK:

    back = enabled;

    break;

    case CSC_NAVIGATEFORWARD:

    forward = enabled;

    break;

    }

    break;

    }

    case DocumentComplete: {

    Variant varResult = event.arguments[0];

    IDispatch dispatch = varResult.getDispatch();

    varResult = event.arguments[1];

    String url = varResult.getString();

    if (html != null && url.equals(ABOUT_BLANK)) {

    Runnable runnable = new Runnable() {

    public void run() {

    if (isDisposed() || html == null)

    return;

    int charCount = html.length();

    char[] chars = new char[charCount];

    html.getChars(0, charCount, chars, 0);

    _text = html;

    html = null;

    int byteCount = OS.WideCharToMultiByte(OS.CP_UTF8, 0, chars, charCount, null, 0, null,

    null);

    /*

    * Note. Internet Explorer appears to treat the

    * data loaded with nsIPersistStreamInit.Load as

    * if it were encoded using the default local

    * charset. There does not seem to be an API to

    * set the desired charset explicitely in this

    * case. The fix is to prepend the UTF-8 Byte

    * Order Mark signature to the data.

    */

    byte[] UTF8BOM = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };

    int hGlobal = OS.GlobalAlloc(OS.GMEM_FIXED, UTF8BOM.length + byteCount);

    if (hGlobal != 0) {

    OS.MoveMemory(hGlobal, UTF8BOM, UTF8BOM.length);

    OS.WideCharToMultiByte(OS.CP_UTF8, 0, chars, charCount, hGlobal + UTF8BOM.length,

    byteCount, null, null);

    int[] ppstm = new int[1];

    /*

    * Note. CreateStreamOnHGlobal is called

    * with the flag fDeleteOnRelease. If the

    * call succeeds the buffer hGlobal is freed

    * automatically when the IStream object is

    * released. If the call fails, free the

    * buffer hGlobal.

    */

    if (OS.CreateStreamOnHGlobal(hGlobal, true, ppstm) == OS.S_OK) {

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Document" }); //$NON-NLS-1$

    Variant pVarResult = auto.getProperty(rgdispid[0]);

    IDispatch dispatchDocument = pVarResult.getDispatch();

    int[] ppvObject = new int[1];

    int result = dispatchDocument.QueryInterface(COM.IIDIPersistStreamInit,

    ppvObject);

    if (result == OS.S_OK) {

    IPersistStreamInit persistStreamInit = new IPersistStreamInit(ppvObject[0]);

    if (persistStreamInit.InitNew() == OS.S_OK) {

    persistStreamInit.Load(ppstm[0]);

    }

    persistStreamInit.Release();

    }

    pVarResult.dispose();

    /*

    * This code is intentionally commented.

    * The IDispatch obtained from a Variant

    * did not increase the reference count

    * for the enclosed interface.

    */

    // dispatchDocument.Release();

    IUnknown stream = new IUnknown(ppstm[0]);

    stream.Release();

    } else {

    OS.GlobalFree(hGlobal);

    }

    }

    }

    };

    if (delaySetText) {

    delaySetText = false;

    getDisplay().asyncExec(runnable);

    } else {

    runnable.run();

    }

    } else {

    setHTML();

    Variant variant = new Variant(auto);

    IDispatch top = variant.getDispatch();

    LocationEvent locationEvent = new LocationEvent(Browser.this);

    locationEvent.display = getDisplay();

    locationEvent.widget = Browser.this;

    locationEvent.location = url;

    locationEvent.top = top.getAddress() == dispatch.getAddress();

    for (int i = 0; i < locationListeners.length; i++)

    locationListeners[i].changed(locationEvent);

    /*

    * This code is intentionally commented. A Variant

    * constructed from an OleAutomation object does not

    * increase its reference count. The IDispatch obtained

    * from this Variant did not increase the reference

    * count for the OleAutomation instance either.

    */

    // top.Release();

    // variant.dispose();

    /*

    * Note. The completion of the page loading is detected

    * as described in the MSDN article "Determine when a

    * page is done loading in WebBrowser Control".

    */

    if (globalDispatch != 0 && dispatch.getAddress() == globalDispatch) {

    /* final document complete */

    globalDispatch = 0;

    ProgressEvent progressEvent = new ProgressEvent(Browser.this);

    progressEvent.display = getDisplay();

    progressEvent.widget = Browser.this;

    for (int i = 0; i < progressListeners.length; i++)

    progressListeners[i].completed(progressEvent);

    }

    }

    /*

    * This code is intentionally commented. This IDispatch was

    * received as an argument from the OleEvent and it will be

    * disposed along with the other arguments.

    */

    // dispatch.Release();

    break;

    }

    case NavigateComplete2: {

    Variant varResult = event.arguments[0];

    IDispatch dispatch = varResult.getDispatch();

    if (globalDispatch == 0)

    globalDispatch = dispatch.getAddress();

    break;

    }

    case NewWindow2: {

    Variant cancel = event.arguments[1];

    int pCancel = cancel.getByRef();

    WindowEvent newEvent = new WindowEvent(Browser.this);

    newEvent.display = getDisplay();

    newEvent.widget = Browser.this;

    newEvent.required = false;

    for (int i = 0; i < openWindowListeners.length; i++)

    openWindowListeners[i].open(newEvent);

    Browser browser = newEvent.browser;

    boolean doit = browser != null && !browser.isDisposed();

    if (doit) {

    Variant variant = new Variant(browser.auto);

    IDispatch iDispatch = variant.getDispatch();

    Variant ppDisp = event.arguments[0];

    int byref = ppDisp.getByRef();

    if (byref != 0)

    COM.MoveMemory(byref, new int[] { iDispatch.getAddress() }, 4);

    /*

    * This code is intentionally commented. A Variant

    * constructed from an OleAutomation object does not

    * increase its reference count. The IDispatch obtained

    * from this Variant did not increase the reference

    * count for the OleAutomation instance either.

    */

    // variant.dispose();

    // iDispatch.Release();

    }

    if (newEvent.required) {

    COM.MoveMemory(pCancel, new short[] { doit ? COM.VARIANT_FALSE : COM.VARIANT_TRUE }, 2);

    }

    break;

    }

    case OnMenuBar: {

    Variant arg0 = event.arguments[0];

    menuBar = arg0.getBoolean();

    break;

    }

    case OnStatusBar: {

    Variant arg0 = event.arguments[0];

    statusBar = arg0.getBoolean();

    break;

    }

    case OnToolBar: {

    Variant arg0 = event.arguments[0];

    toolBar = arg0.getBoolean();

    /*

    * Feature in Internet Explorer. OnToolBar FALSE is emitted

    * when both tool bar, address bar and menu bar must not be

    * visible. OnToolBar TRUE is emitted when either of tool

    * bar, address bar or menu bar is visible.

    */

    if (!toolBar) {

    addressBar = false;

    menuBar = false;

    }

    break;

    }

    case OnVisible: {

    Variant arg1 = event.arguments[0];

    boolean visible = arg1.getBoolean();

    WindowEvent newEvent = new WindowEvent(Browser.this);

    newEvent.display = getDisplay();

    newEvent.widget = Browser.this;

    if (visible) {

    if (addressBar) {

    /*

    * Bug in Internet Explorer. There is no distinct

    * notification for the address bar. If neither

    * address, menu or tool bars are visible, OnToolBar

    * FALSE is emitted. For some reason, querying the

    * value of AddressBar in this case returns true

    * even though it should not be set visible. The

    * workaround is to only query the value of

    * AddressBar when OnToolBar FALSE has not been

    * emitted.

    */

    int[] rgdispid = auto.getIDsOfNames(new String[] { "AddressBar" }); //$NON-NLS-1$

    Variant pVarResult = auto.getProperty(rgdispid[0]);

    if (pVarResult != null && pVarResult.getType() == OLE.VT_BOOL)

    addressBar = pVarResult.getBoolean();

    }

    newEvent.addressBar = addressBar;

    newEvent.menuBar = menuBar;

    newEvent.statusBar = statusBar;

    newEvent.toolBar = toolBar;

    newEvent.location = location;

    newEvent.size = size;

    for (int i = 0; i < visibilityWindowListeners.length; i++) {

    visibilityWindowListeners[i].show(newEvent);

    }

    location = null;

    size = null;

    } else {

    for (int i = 0; i < visibilityWindowListeners.length; i++)

    visibilityWindowListeners[i].hide(newEvent);

    }

    break;

    }

    case ProgressChange: {

    Variant arg1 = event.arguments[0];

    int nProgress = arg1.getType() != OLE.VT_I4 ? 0 : arg1.getInt(); // may

    // be

    // -1

    Variant arg2 = event.arguments[1];

    int nProgressMax = arg2.getType() != OLE.VT_I4 ? 0 : arg2.getInt();

    ProgressEvent newEvent = new ProgressEvent(Browser.this);

    newEvent.display = getDisplay();

    newEvent.widget = Browser.this;

    newEvent.current = nProgress;

    newEvent.total = nProgressMax;

    if (nProgress != -1) {

    for (int i = 0; i < progressListeners.length; i++)

    progressListeners[i].changed(newEvent);

    }

    break;

    }

    case StatusTextChange: {

    Variant arg1 = event.arguments[0];

    if (arg1.getType() == OLE.VT_BSTR) {

    String text = arg1.getString();

    StatusTextEvent newEvent = new StatusTextEvent(Browser.this);

    newEvent.display = getDisplay();

    newEvent.widget = Browser.this;

    newEvent.text = text;

    for (int i = 0; i < statusTextListeners.length; i++)

    statusTextListeners[i].changed(newEvent);

    }

    break;

    }

    case TitleChange: {

    Variant arg1 = event.arguments[0];

    if (arg1.getType() == OLE.VT_BSTR) {

    String title = arg1.getString();

    TitleEvent newEvent = new TitleEvent(Browser.this);

    newEvent.display = getDisplay();

    newEvent.widget = Browser.this;

    newEvent.title = title;

    for (int i = 0; i < titleListeners.length; i++)

    titleListeners[i].changed(newEvent);

    }

    break;

    }

    case WindowClosing: {

    WindowEvent newEvent = new WindowEvent(Browser.this);

    newEvent.display = getDisplay();

    newEvent.widget = Browser.this;

    for (int i = 0; i < closeWindowListeners.length; i++)

    closeWindowListeners[i].close(newEvent);

    Variant cancel = event.arguments[1];

    int pCancel = cancel.getByRef();

    COM.MoveMemory(pCancel, new short[] { COM.VARIANT_FALSE }, 2);

    dispose();

    break;

    }

    case WindowSetHeight: {

    if (size == null)

    size = new Point(0, 0);

    Variant arg1 = event.arguments[0];

    size.y = arg1.getInt();

    break;

    }

    case WindowSetLeft: {

    if (location == null)

    location = new Point(0, 0);

    Variant arg1 = event.arguments[0];

    location.x = arg1.getInt();

    break;

    }

    case WindowSetTop: {

    if (location == null)

    location = new Point(0, 0);

    Variant arg1 = event.arguments[0];

    location.y = arg1.getInt();

    break;

    }

    case WindowSetWidth: {

    if (size == null)

    size = new Point(0, 0);

    Variant arg1 = event.arguments[0];

    size.x = arg1.getInt();

    break;

    }

    }

    /*

    * Dispose all arguments passed in the OleEvent. This must be

    * done to properly release any IDispatch reference that was

    * automatically addRef'ed when constructing the OleEvent.

    */

    Variant[] arguments = event.arguments;

    for (int i = 0; i < arguments.length; i++)

    arguments[i].dispose();

    }

    };

    site.addEventListener(BeforeNavigate2, oleListener);

    site.addEventListener(CommandStateChange, oleListener);

    site.addEventListener(DocumentComplete, oleListener);

    site.addEventListener(NavigateComplete2, oleListener);

    site.addEventListener(NewWindow2, oleListener);

    site.addEventListener(OnMenuBar, oleListener);

    site.addEventListener(OnStatusBar, oleListener);

    site.addEventListener(OnToolBar, oleListener);

    site.addEventListener(OnVisible, oleListener);

    site.addEventListener(ProgressChange, oleListener);

    site.addEventListener(StatusTextChange, oleListener);

    site.addEventListener(TitleChange, oleListener);

    site.addEventListener(WindowClosing, oleListener);

    site.addEventListener(WindowSetHeight, oleListener);

    site.addEventListener(WindowSetLeft, oleListener);

    site.addEventListener(WindowSetTop, oleListener);

    site.addEventListener(WindowSetWidth, oleListener);

    Variant variant = new Variant(true);

    auto.setProperty(RegisterAsBrowser, variant);

    variant.dispose();

    variant = new Variant(false);

    int[] rgdispid = auto.getIDsOfNames(new String[] { "RegisterAsDropTarget" }); //$NON-NLS-1$

    if (rgdispid != null)

    auto.setProperty(rgdispid[0], variant);

    variant.dispose();

    }

    /**

    * Adds the listener to the collection of listeners who will be notified

    * when the window hosting the receiver should be closed.

    *

    * This notification occurs when a javascript command such as

    * window.close gets executed by a Browser.

    *

    *

    * @param listener

    *            the listener which should be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void addCloseWindowListener(CloseWindowListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    CloseWindowListener[] newCloseWindowListeners = new CloseWindowListener[closeWindowListeners.length + 1];

    System.arraycopy(closeWindowListeners, 0, newCloseWindowListeners, 0, closeWindowListeners.length);

    closeWindowListeners = newCloseWindowListeners;

    closeWindowListeners[closeWindowListeners.length - 1] = listener;

    }

    /**

    * Adds the listener to the collection of listeners who will be notified

    * when the current location has changed or is about to change.

    *

    * This notification typically occurs when the application navigates to a

    * new location with {@link #setUrl(String)} or when the user activates a

    * hyperlink.

    *

    *

    * @param listener

    *            the listener which should be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void addLocationListener(LocationListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    LocationListener[] newLocationListeners = new LocationListener[locationListeners.length + 1];

    System.arraycopy(locationListeners, 0, newLocationListeners, 0, locationListeners.length);

    locationListeners = newLocationListeners;

    locationListeners[locationListeners.length - 1] = listener;

    }

    /**

    * Adds the listener to the collection of listeners who will be notified

    * when a new window needs to be created.

    *

    * This notification occurs when a javascript command such as

    * window.open gets executed by a Browser.

    *

    *

    * @param listener

    *            the listener which should be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void addOpenWindowListener(OpenWindowListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    OpenWindowListener[] newOpenWindowListeners = new OpenWindowListener[openWindowListeners.length + 1];

    System.arraycopy(openWindowListeners, 0, newOpenWindowListeners, 0, openWindowListeners.length);

    openWindowListeners = newOpenWindowListeners;

    openWindowListeners[openWindowListeners.length - 1] = listener;

    }

    /**

    * Adds the listener to the collection of listeners who will be notified

    * when a progress is made during the loading of the current URL or when the

    * loading of the current URL has been completed.

    *

    * @param listener

    *            the listener which should be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void addProgressListener(ProgressListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    ProgressListener[] newProgressListeners = new ProgressListener[progressListeners.length + 1];

    System.arraycopy(progressListeners, 0, newProgressListeners, 0, progressListeners.length);

    progressListeners = newProgressListeners;

    progressListeners[progressListeners.length - 1] = listener;

    }

    /**

    * Adds the listener to the collection of listeners who will be notified

    * when the status text is changed.

    *

    * The status text is typically displayed in the status bar of a browser

    * application.

    *

    *

    * @param listener

    *            the listener which should be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void addStatusTextListener(StatusTextListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    StatusTextListener[] newStatusTextListeners = new StatusTextListener[statusTextListeners.length + 1];

    System.arraycopy(statusTextListeners, 0, newStatusTextListeners, 0, statusTextListeners.length);

    statusTextListeners = newStatusTextListeners;

    statusTextListeners[statusTextListeners.length - 1] = listener;

    }

    /**

    * Adds the listener to the collection of listeners who will be notified

    * when the title of the current document is available or has changed.

    *

    * @param listener

    *            the listener which should be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void addTitleListener(TitleListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    TitleListener[] newTitleListeners = new TitleListener[titleListeners.length + 1];

    System.arraycopy(titleListeners, 0, newTitleListeners, 0, titleListeners.length);

    titleListeners = newTitleListeners;

    titleListeners[titleListeners.length - 1] = listener;

    }

    /**

    * Adds the listener to the collection of listeners who will be notified

    * when a window hosting the receiver needs to be displayed or hidden.

    *

    * @param listener

    *            the listener which should be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void addVisibilityWindowListener(VisibilityWindowListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    VisibilityWindowListener[] newVisibilityWindowListeners = new VisibilityWindowListener[visibilityWindowListeners.length + 1];

    System.arraycopy(visibilityWindowListeners, 0, newVisibilityWindowListeners, 0,

    visibilityWindowListeners.length);

    visibilityWindowListeners = newVisibilityWindowListeners;

    visibilityWindowListeners[visibilityWindowListeners.length - 1] = listener;

    }

    /**

    * Navigate to the previous session history item.

    *

    * @return true if the operation was successful and

    *         false otherwise

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @see #forward

    *

    * @since 3.0

    */

    public boolean back() {

    checkWidget();

    if (!back)

    return false;

    int[] rgdispid = auto.getIDsOfNames(new String[] { "GoBack" }); //$NON-NLS-1$

    Variant pVarResult = auto.invoke(rgdispid[0]);

    return pVarResult != null && pVarResult.getType() == OLE.VT_EMPTY;

    }

    protected void checkSubclass() {

    String name = getClass().getName();

    int index = name.lastIndexOf('.');

    if (!name.substring(0, index + 1).equals(PACKAGE_PREFIX)) {

    SWT.error(SWT.ERROR_INVALID_SUBCLASS);

    }

    }

    /**

    * Execute the specified script.

    *

    *

    * Execute a script containing javascript commands in the context of the

    * current document.

    *

    * @param script

    *            the script with javascript commands

    *

    * @return true if the operation was successful and

    *         false otherwise

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the script is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.1

    */

    public boolean execute(String script) {

    checkWidget();

    if (script == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    /* get IHTMLDocument2 */

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Document" }); //$NON-NLS-1$

    int dispIdMember = rgdispid[0];

    Variant pVarResult = auto.getProperty(dispIdMember);

    if (pVarResult == null || pVarResult.getType() == COM.VT_EMPTY)

    return false;

    OleAutomation document = pVarResult.getAutomation();

    pVarResult.dispose();

    /* get IHTMLWindow2 */

    rgdispid = document.getIDsOfNames(new String[] { "parentWindow" }); //$NON-NLS-1$

    dispIdMember = rgdispid[0];

    pVarResult = document.getProperty(dispIdMember);

    OleAutomation ihtmlWindow2 = pVarResult.getAutomation();

    pVarResult.dispose();

    document.dispose();

    rgdispid = ihtmlWindow2.getIDsOfNames(new String[] { "execScript", "code" }); //$NON-NLS-1$  //$NON-NLS-2$

    Variant[] rgvarg = new Variant[1];

    rgvarg[0] = new Variant(script);

    int[] rgdispidNamedArgs = new int[1];

    rgdispidNamedArgs[0] = rgdispid[1];

    pVarResult = ihtmlWindow2.invoke(rgdispid[0], rgvarg, rgdispidNamedArgs);

    rgvarg[0].dispose();

    ihtmlWindow2.dispose();

    if (pVarResult == null)

    return false;

    pVarResult.dispose();

    return true;

    }

    /**

    * Navigate to the next session history item.

    *

    * @return true if the operation was successful and

    *         false otherwise

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @see #back

    *

    * @since 3.0

    */

    public boolean forward() {

    checkWidget();

    if (!forward)

    return false;

    int[] rgdispid = auto.getIDsOfNames(new String[] { "GoForward" }); //$NON-NLS-1$

    Variant pVarResult = auto.invoke(rgdispid[0]);

    return pVarResult != null && pVarResult.getType() == OLE.VT_EMPTY;

    }

    /**

    * Returns true if the receiver can navigate to the previous

    * session history item, and false otherwise.

    *

    * @return the receiver's back command enabled state

    *

    * @exception SWTException

    *               

    *               

    ERROR_WIDGET_DISPOSED - if the receiver has been

    *                disposed

    *               

    ERROR_THREAD_INVALID_ACCESS - if not called from the

    *                thread that created the receiver

    *               

    *

    * @see #back

    */

    public boolean isBackEnabled() {

    checkWidget();

    return back;

    }

    /**

    * Returns true if the receiver can navigate to the next

    * session history item, and false otherwise.

    *

    * @return the receiver's forward command enabled state

    *

    * @exception SWTException

    *               

    *               

    ERROR_WIDGET_DISPOSED - if the receiver has been

    *                disposed

    *               

    ERROR_THREAD_INVALID_ACCESS - if not called from the

    *                thread that created the receiver

    *               

    *

    * @see #forward

    */

    public boolean isForwardEnabled() {

    checkWidget();

    return forward;

    }

    /**

    * Returns the current URL.

    *

    * @return the current URL or an empty String if there is no

    *         current URL

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @see #setUrl

    *

    * @since 3.0

    */

    public String getUrl() {

    checkWidget();

    int[] rgdispid = auto.getIDsOfNames(new String[] { "LocationURL" }); //$NON-NLS-1$

    Variant pVarResult = auto.getProperty(rgdispid[0]);

    if (pVarResult == null || pVarResult.getType() != OLE.VT_BSTR)

    return "";

    String result = pVarResult.getString();

    pVarResult.dispose();

    return result;

    }

    /**

    * Refresh the current page.

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void refresh() {

    checkWidget();

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Refresh" }); //$NON-NLS-1$

    auto.invoke(rgdispid[0]);

    }

    /**

    * Removes the listener from the collection of listeners who will be

    * notified when the window hosting the receiver should be closed.

    *

    * @param listener

    *            the listener which should no longer be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void removeCloseWindowListener(CloseWindowListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    if (closeWindowListeners.length == 0)

    return;

    int index = -1;

    for (int i = 0; i < closeWindowListeners.length; i++) {

    if (listener == closeWindowListeners[i]) {

    index = i;

    break;

    }

    }

    if (index == -1)

    return;

    if (closeWindowListeners.length == 1) {

    closeWindowListeners = new CloseWindowListener[0];

    return;

    }

    CloseWindowListener[] newCloseWindowListeners = new CloseWindowListener[closeWindowListeners.length - 1];

    System.arraycopy(closeWindowListeners, 0, newCloseWindowListeners, 0, index);

    System.arraycopy(closeWindowListeners, index + 1, newCloseWindowListeners, index, closeWindowListeners.length

    - index - 1);

    closeWindowListeners = newCloseWindowListeners;

    }

    /**

    * Removes the listener from the collection of listeners who will be

    * notified when the current location is changed or about to be changed.

    *

    * @param listener

    *            the listener which should no longer be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void removeLocationListener(LocationListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    if (locationListeners.length == 0)

    return;

    int index = -1;

    for (int i = 0; i < locationListeners.length; i++) {

    if (listener == locationListeners[i]) {

    index = i;

    break;

    }

    }

    if (index == -1)

    return;

    if (locationListeners.length == 1) {

    locationListeners = new LocationListener[0];

    return;

    }

    LocationListener[] newLocationListeners = new LocationListener[locationListeners.length - 1];

    System.arraycopy(locationListeners, 0, newLocationListeners, 0, index);

    System.arraycopy(locationListeners, index + 1, newLocationListeners, index, locationListeners.length - index

    - 1);

    locationListeners = newLocationListeners;

    }

    /**

    * Removes the listener from the collection of listeners who will be

    * notified when a new window needs to be created.

    *

    * @param listener

    *            the listener which should no longer be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void removeOpenWindowListener(OpenWindowListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    if (openWindowListeners.length == 0)

    return;

    int index = -1;

    for (int i = 0; i < openWindowListeners.length; i++) {

    if (listener == openWindowListeners[i]) {

    index = i;

    break;

    }

    }

    if (index == -1)

    return;

    if (openWindowListeners.length == 1) {

    openWindowListeners = new OpenWindowListener[0];

    return;

    }

    OpenWindowListener[] newOpenWindowListeners = new OpenWindowListener[openWindowListeners.length - 1];

    System.arraycopy(openWindowListeners, 0, newOpenWindowListeners, 0, index);

    System.arraycopy(openWindowListeners, index + 1, newOpenWindowListeners, index, openWindowListeners.length

    - index - 1);

    openWindowListeners = newOpenWindowListeners;

    }

    /**

    * Removes the listener from the collection of listeners who will be

    * notified when a progress is made during the loading of the current URL or

    * when the loading of the current URL has been completed.

    *

    * @param listener

    *            the listener which should no longer be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void removeProgressListener(ProgressListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    if (progressListeners.length == 0)

    return;

    int index = -1;

    for (int i = 0; i < progressListeners.length; i++) {

    if (listener == progressListeners[i]) {

    index = i;

    break;

    }

    }

    if (index == -1)

    return;

    if (progressListeners.length == 1) {

    progressListeners = new ProgressListener[0];

    return;

    }

    ProgressListener[] newProgressListeners = new ProgressListener[progressListeners.length - 1];

    System.arraycopy(progressListeners, 0, newProgressListeners, 0, index);

    System.arraycopy(progressListeners, index + 1, newProgressListeners, index, progressListeners.length - index

    - 1);

    progressListeners = newProgressListeners;

    }

    /**

    * Removes the listener from the collection of listeners who will be

    * notified when the status text is changed.

    *

    * @param listener

    *            the listener which should no longer be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void removeStatusTextListener(StatusTextListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    if (statusTextListeners.length == 0)

    return;

    int index = -1;

    for (int i = 0; i < statusTextListeners.length; i++) {

    if (listener == statusTextListeners[i]) {

    index = i;

    break;

    }

    }

    if (index == -1)

    return;

    if (statusTextListeners.length == 1) {

    statusTextListeners = new StatusTextListener[0];

    return;

    }

    StatusTextListener[] newStatusTextListeners = new StatusTextListener[statusTextListeners.length - 1];

    System.arraycopy(statusTextListeners, 0, newStatusTextListeners, 0, index);

    System.arraycopy(statusTextListeners, index + 1, newStatusTextListeners, index, statusTextListeners.length

    - index - 1);

    statusTextListeners = newStatusTextListeners;

    }

    /**

    * Removes the listener from the collection of listeners who will be

    * notified when the title of the current document is available or has

    * changed.

    *

    * @param listener

    *            the listener which should no longer be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void removeTitleListener(TitleListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    if (titleListeners.length == 0)

    return;

    int index = -1;

    for (int i = 0; i < titleListeners.length; i++) {

    if (listener == titleListeners[i]) {

    index = i;

    break;

    }

    }

    if (index == -1)

    return;

    if (titleListeners.length == 1) {

    titleListeners = new TitleListener[0];

    return;

    }

    TitleListener[] newTitleListeners = new TitleListener[titleListeners.length - 1];

    System.arraycopy(titleListeners, 0, newTitleListeners, 0, index);

    System.arraycopy(titleListeners, index + 1, newTitleListeners, index, titleListeners.length - index - 1);

    titleListeners = newTitleListeners;

    }

    /**

    * Removes the listener from the collection of listeners who will be

    * notified when a window hosting the receiver needs to be displayed or

    * hidden.

    *

    * @param listener

    *            the listener which should no longer be notified

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the listener is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void removeVisibilityWindowListener(VisibilityWindowListener listener) {

    checkWidget();

    if (listener == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    if (visibilityWindowListeners.length == 0)

    return;

    int index = -1;

    for (int i = 0; i < visibilityWindowListeners.length; i++) {

    if (listener == visibilityWindowListeners[i]) {

    index = i;

    break;

    }

    }

    if (index == -1)

    return;

    if (visibilityWindowListeners.length == 1) {

    visibilityWindowListeners = new VisibilityWindowListener[0];

    return;

    }

    VisibilityWindowListener[] newVisibilityWindowListeners = new VisibilityWindowListener[visibilityWindowListeners.length - 1];

    System.arraycopy(visibilityWindowListeners, 0, newVisibilityWindowListeners, 0, index);

    System.arraycopy(visibilityWindowListeners, index + 1, newVisibilityWindowListeners, index,

    visibilityWindowListeners.length - index - 1);

    visibilityWindowListeners = newVisibilityWindowListeners;

    }

    /**

    * Renders HTML.

    *

    *

    * The html parameter is Unicode encoded since it is a java

    * String. As a result, the HTML meta tag charset should not

    * be set. The charset is implied by the String itself.

    *

    * @param html

    *            the HTML content to be rendered

    *

    * @return true if the operation was successful and false otherwise.

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the html is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @see #setUrl

    *

    * @since 3.0

    */

    public boolean setText(String html) {

    checkWidget();

    if (html == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    /*

    * If the html field is non-null then the about:blank page is already

    * being loaded, so no Stop or Navigate is required. Just set the html

    * that is to be shown.

    */

    boolean blankLoading = this.html != null;

    this.html = html;

    if (blankLoading)

    return true;

    /*

    * Navigate to the blank page and insert the given html when receiving

    * the next DocumentComplete notification. See the MSDN article "Loading

    * HTML content from a Stream".

    *

    * Note. Stop any pending request. This is required to avoid displaying

    * a blank page as a result of consecutive calls to setUrl and/or

    * setText. The previous request would otherwise render the new html

    * content and reset the html field before the browser actually

    * navigates to the blank page as requested below.

    *

    * Feature in Internet Explorer. Stopping pending requests when no

    * request is pending causes a default page 'Action cancelled' to be

    * displayed. The workaround is to not invoke 'stop' when no request has

    * been set since that instance was created.

    */

    int[] rgdispid;

    if (navigate) {

    /*

    * Stopping the loading of a page causes DocumentComplete events

    * from previous requests to be received before the DocumentComplete

    * for this page. In such cases we must be sure to not set the html

    * into the browser too soon, since doing so could result in its

    * page being cleared out by a subsequent DocumentComplete. The

    * Browser's ReadyState can be used to determine whether these extra

    * events will be received or not.

    */

    rgdispid = auto.getIDsOfNames(new String[] { "ReadyState" }); //$NON-NLS-1$

    Variant pVarResult = auto.getProperty(rgdispid[0]);

    if (pVarResult == null)

    return false;

    delaySetText = pVarResult.getInt() != READYSTATE_COMPLETE;

    pVarResult.dispose();

    rgdispid = auto.getIDsOfNames(new String[] { "Stop" }); //$NON-NLS-1$

    auto.invoke(rgdispid[0]);

    }

    rgdispid = auto.getIDsOfNames(new String[] { "Navigate", "URL" }); //$NON-NLS-1$ //$NON-NLS-2$

    navigate = true;

    Variant[] rgvarg = new Variant[1];

    rgvarg[0] = new Variant(ABOUT_BLANK);

    int[] rgdispidNamedArgs = new int[1];

    rgdispidNamedArgs[0] = rgdispid[1];

    Variant pVarResult = auto.invoke(rgdispid[0], rgvarg, rgdispidNamedArgs);

    rgvarg[0].dispose();

    if (pVarResult == null)

    return false;

    boolean result = pVarResult.getType() == OLE.VT_EMPTY;

    pVarResult.dispose();

    return result;

    }

    /**

    * Loads a URL.

    *

    * @param url

    *            the URL to be loaded

    *

    * @return true if the operation was successful and false otherwise.

    *

    * @exception IllegalArgumentException

    *               

    *               

    ERROR_NULL_ARGUMENT - if the url is null

    *               

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @see #getUrl

    *

    * @since 3.0

    */

    public boolean setUrl(String url) {

    checkWidget();

    if (url == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    html = null;

    /*

    * Bug in Internet Explorer. For some reason, Navigating to an xml

    * document before a previous Navigate has completed will leave the

    * Browser in a bad state if the Navigate to the xml document does not

    * complete. This bad state causes a GP when the parent window is

    * eventually disposed. The workaround is to issue a Stop before

    * navigating to any xml document.

    */

    if (url.endsWith(".xml")) { //$NON-NLS-1$

    /*

    * Feature in Internet Explorer. Stopping pending requests when no

    * request has been issued causes a default 'Action cancelled' page

    * to be displayed. Since Stop must be issued here, the workaround

    * is to first Navigate to the about:blank page before issuing Stop

    * so that the 'Action cancelled' page is not displayed.

    */

    if (!navigate) {

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Navigate", "URL" }); //$NON-NLS-1$ //$NON-NLS-2$

    Variant[] rgvarg = new Variant[1];

    rgvarg[0] = new Variant(ABOUT_BLANK);

    int[] rgdispidNamedArgs = new int[1];

    rgdispidNamedArgs[0] = rgdispid[1];

    auto.invoke(rgdispid[0], rgvarg, rgdispidNamedArgs);

    rgvarg[0].dispose();

    }

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Stop" }); //$NON-NLS-1$

    auto.invoke(rgdispid[0]);

    }

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Navigate", "URL" }); //$NON-NLS-1$ //$NON-NLS-2$

    navigate = true;

    Variant[] rgvarg = new Variant[1];

    rgvarg[0] = new Variant(url);

    int[] rgdispidNamedArgs = new int[1];

    rgdispidNamedArgs[0] = rgdispid[1];

    Variant pVarResult = auto.invoke(rgdispid[0], rgvarg, rgdispidNamedArgs);

    rgvarg[0].dispose();

    if (pVarResult == null)

    return false;

    boolean result = pVarResult.getType() == OLE.VT_EMPTY;

    pVarResult.dispose();

    return result;

    }

    public boolean setUrl(String url, String postData) {

    checkWidget();

    if (url == null)

    SWT.error(SWT.ERROR_NULL_ARGUMENT);

    html = null;

    /*

    * Bug in Internet Explorer. For some reason, Navigating to an xml

    * document before a previous Navigate has completed will leave the

    * Browser in a bad state if the Navigate to the xml document does not

    * complete. This bad state causes a GP when the parent window is

    * eventually disposed. The workaround is to issue a Stop before

    * navigating to any xml document.

    */

    if (url.endsWith(".xml")) { //$NON-NLS-1$

    /*

    * Feature in Internet Explorer. Stopping pending requests when no

    * request has been issued causes a default 'Action cancelled' page

    * to be displayed. Since Stop must be issued here, the workaround

    * is to first Navigate to the about:blank page before issuing Stop

    * so that the 'Action cancelled' page is not displayed.

    */

    if (!navigate) {

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Navigate", "URL" }); //$NON-NLS-1$ //$NON-NLS-2$

    Variant[] rgvarg = new Variant[1];

    rgvarg[0] = new Variant(ABOUT_BLANK);

    int[] rgdispidNamedArgs = new int[1];

    rgdispidNamedArgs[0] = rgdispid[1];

    auto.invoke(rgdispid[0], rgvarg, rgdispidNamedArgs);

    rgvarg[0].dispose();

    }

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Stop" }); //$NON-NLS-1$

    auto.invoke(rgdispid[0]);

    }

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Navigate", "URL", "PostData" }); //$NON-NLS-1$ //$NON-NLS-2$

    navigate = true;

    Variant[] rgvarg = new Variant[2];

    rgvarg[0] = new Variant(url);

    rgvarg[1] = writeSafeArray(postData);

    int[] rgdispidNamedArgs = new int[2];

    rgdispidNamedArgs[0] = rgdispid[1];

    rgdispidNamedArgs[1] = rgdispid[2];

    Variant pVarResult = auto.invoke(rgdispid[0], rgvarg, rgdispidNamedArgs);

    //  int[] rgdispid = automation.getIDsOfNames(new String[] { "Navigate", "URL", "PostData" });

    //  int dispIdMember = rgdispid[0];

    //  Variant[] rgvarg = new Variant[2];

    //  rgvarg[0] = new Variant(text.getText());

    //  rgvarg[1] = writeSafeArray("hello world");

    //  int[] rgdispidNamedArgs = new int[2];

    //  rgdispidNamedArgs[0] = rgdispid[1];

    //  rgdispidNamedArgs[1] = rgdispid[2];

    //  automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);

    rgvarg[0].dispose();

    if (pVarResult == null)

    return false;

    boolean result = pVarResult.getType() == OLE.VT_EMPTY;

    pVarResult.dispose();

    return result;

    }

    /**

    * Stop any loading and rendering activity.

    *

    * @exception SWTException

    *               

    *               

    ERROR_THREAD_INVALID_ACCESS when called from the

    *                wrong thread

    *               

    ERROR_WIDGET_DISPOSED when the widget has been

    *                disposed

    *               

    *

    * @since 3.0

    */

    public void stop() {

    checkWidget();

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Stop" }); //$NON-NLS-1$

    auto.invoke(rgdispid[0]);

    }

    static String readSafeArray(Variant variantByRef) {

    // Read a safearray that contains data of

    // type VT_UI1 (unsigned shorts) which contains

    // a text stream.

    int pPostData = variantByRef.getByRef();

    short[] vt_type = new short[1];

    OS.MoveMemory(vt_type, pPostData, 2);

    String result = null;

    if (vt_type[0] == (short) (OLE.VT_BYREF | OLE.VT_VARIANT)) {

    int[] pVariant = new int[1];

    OS.MoveMemory(pVariant, pPostData + 8, 4);

    vt_type = new short[1];

    OS.MoveMemory(vt_type, pVariant[0], 2);

    if (vt_type[0] == (short) (OLE.VT_ARRAY | OLE.VT_UI1)) {

    int[] pSafearray = new int[1];

    OS.MoveMemory(pSafearray, pVariant[0] + 8, 4);

    short[] cDims = new short[1];

    OS.MoveMemory(cDims, pSafearray[0], 2);

    int[] pvData = new int[1];

    OS.MoveMemory(pvData, pSafearray[0] + 12, 4);

    int safearrayboundOffset = 0;

    for (int i = 0; i < cDims[0]; i++) {

    int[] cElements = new int[1];

    OS.MoveMemory(cElements, pSafearray[0] + 16 + safearrayboundOffset, 4);

    safearrayboundOffset += 8;

    int cchWideChar = OS.MultiByteToWideChar(CodePage, OS.MB_PRECOMPOSED, pvData[0], -1, null, 0);

    if (cchWideChar == 0)

    return null;

    char[] lpWideCharStr = new char[cchWideChar - 1];

    OS.MultiByteToWideChar(CodePage, OS.MB_PRECOMPOSED, pvData[0], -1, lpWideCharStr,

    lpWideCharStr.length);

    result = new String(lpWideCharStr);

    }

    }

    }

    return result;

    }

    static Variant writeSafeArray(String string) {

    // Create a one dimensional safearray containing two VT_UI1 values

    // where VT_UI1 is an unsigned char

    // Define cDims, fFeatures and cbElements

    short cDims = 1;

    short FADF_FIXEDSIZE = 0x10;

    short FADF_HAVEVARTYPE = 0x80;

    short fFeatures = (short) (FADF_FIXEDSIZE | FADF_HAVEVARTYPE);

    int cbElements = 1;

    // Create a pointer and copy the data into it

    int count = string.length();

    char[] chars = new char[count + 1];

    string.getChars(0, count, chars, 0);

    int cchMultiByte = OS.WideCharToMultiByte(CodePage, 0, chars, -1, null, 0, null, null);

    if (cchMultiByte == 0)

    return null;

    int pvData = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, cchMultiByte);

    OS.WideCharToMultiByte(CodePage, 0, chars, -1, pvData, cchMultiByte, null, null);

    int cElements1 = cchMultiByte;

    int lLbound1 = 0;

    // Create a safearray in memory

    // 12 bytes for cDims, fFeatures and cbElements + 4 bytes for pvData +

    // number of dimensions * (size of safearraybound)

    int sizeofSafeArray = 12 + 4 + 1 * 8;

    int pSafeArray = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, sizeofSafeArray);

    // Copy the data into the safe array

    int offset = 0;

    OS.MoveMemory(pSafeArray + offset, new short[] { cDims }, 2);

    offset += 2;

    OS.MoveMemory(pSafeArray + offset, new short[] { fFeatures }, 2);

    offset += 2;

    OS.MoveMemory(pSafeArray + offset, new int[] { cbElements }, 4);

    offset += 4;

    OS.MoveMemory(pSafeArray + offset, new int[] { 0 }, 4);

    offset += 4;

    OS.MoveMemory(pSafeArray + offset, new int[] { pvData }, 4);

    offset += 4;

    OS.MoveMemory(pSafeArray + offset, new int[] { cElements1 }, 4);

    offset += 4;

    OS.MoveMemory(pSafeArray + offset, new int[] { lLbound1 }, 4);

    offset += 4;

    // Create a variant in memory to hold the safearray

    int pVariant = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, Variant.sizeof);

    short vt = (short) (OLE.VT_ARRAY | OLE.VT_UI1);

    OS.MoveMemory(pVariant, new short[] { vt }, 2);

    OS.MoveMemory(pVariant + 8, new int[] { pSafeArray }, 4);

    // Create a by ref variant

    Variant variantByRef = new Variant(pVariant, (short) (OLE.VT_BYREF | OLE.VT_VARIANT));

    return variantByRef;

    }

    public int getBrowserId() {

    return this.browserId;

    }

    public String getText() {

    return _text;

    }

    /**

    * Modified by TMB on 8/15/2005

    *

    * Sets the html between the root node of the Document automation object.

    * The root node will generally start at the node

    *

    * From MSDN: With Internet Explorer 6 and later, when you use the !DOCTYPE

    * declaration to specify standards-compliant mode, this element represents

    * the canvas—the entire surface onto which a document's contents can be

    * rendered. When you switch on standards-compliant mode, this element also

    * becomes the positioning container for positioned elements that don't have

    * a positioned parent. When the !DOCTYPE declaration does not specify

    * standards-compliant mode, and with earler versions of Internet Explorer,

    * the body object represents the entire surface onto which a document's

    * contents can be rendered.

    *

    * By retrieving the documentElement, we do not care what tag represents the

    * canvas. This method allows us to take what we are given and work with it,

    * including malformed HTML.

    *

    */

    private void setHTML() {

    Variant pVarResult = null;

    OleAutomation autox = null;

    int[] rgdispid = auto.getIDsOfNames(new String[] { "Document" }); //$NON-NLS-1$

    if (rgdispid != null) {

    pVarResult = auto.getProperty(rgdispid[0]);

    autox = pVarResult.getAutomation();

    rgdispid = autox.getIDsOfNames(new String[] { "documentElement" });

    if (rgdispid != null) {

    pVarResult = autox.getProperty(rgdispid[0]);

    autox = pVarResult.getAutomation();

    rgdispid = autox.getIDsOfNames(new String[] { "innerHTML" });

    if (rgdispid != null) {

    pVarResult = autox.getProperty(rgdispid[0]);

    _text = pVarResult.getString();

    }

    }

    }

    // be sure to dispose of any native references so that Release() is

    // called on their IUnknown pointer

    if (pVarResult != null) {

    pVarResult.dispose();

    }

    if (autox != null) {

    autox.dispose();

    }

    }

    }

    posted on 2005-11-30 10:25 亘古顽石 阅读(3630) 评论(2)  编辑  收藏

    展开全文
  • 如题,我做了一个网站,如下代码,现在的问题是网站可以修改,但是一旦刷新或重新登录后又恢复原状了。 请问改写什么代码才能保存网页修改的信息? ``` <%@ page import ="java.util.*" contentType=...
  • 由于之前使用eclipse的习惯,在当前A页面按住ctrl跳转到另一个java文件(B页面),再关闭B页面就会回到A页面。 但是idea默认的不是这样的,默认的总是关闭页面之后打开该页面相邻的左侧界面,下面就来描述怎么修改。 ...

    由于之前使用eclipse的习惯,在当前A页面按住ctrl跳转到另一个java文件(B页面),再关闭B页面就会回到A页面。

    但是idea默认的不是这样的,默认的总是关闭页面之后打开该页面相邻的左侧界面,下面就来描述怎么修改。

    方法很简单:

    File -> Settings -> Editor -> General -> Editor Tabs :

    展开全文
  • 本篇博客是java对mysql的简单操作的综合运用——登录系统java对mysql的简单操作的综合运用——注册系统java对mysql的简单操作的综合运用——修改密码...代码如下(注:dispose()的作用是关闭当前的界面) import java

    本篇博客是java对mysql的简单操作的综合运用——登录系统java对mysql的简单操作的综合运用——注册系统java对mysql的简单操作的综合运用——修改密码系统的整合。
    因为使用的是数据库中的数据,故代码中会有很多代码是有关数据库的,如有疑问,最下方传送门。

    整合后的代码共四个界面,分别是登录界面注册界面菜单界面修改密码界面

    登录界面

    登录界面在原来的基础上设置了用户密码的隐私保护,并且给按钮设置了页面跳转。

    代码如下(注:dispose()的作用是关闭当前的界面)

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    
    public class login extends JFrame implements ActionListener{
    	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    	static final String DB_URL = "jdbc:mysql://localhost:3306/message";
    	static final String USER = "root";
        static final String PASS = "123456";
    	JButton jb1=new JButton("登录");
    	JButton jb2=new JButton("注册");
    	JLabel jl1=new JLabel("账号:");
    	JLabel jl2=new JLabel("密码:");
    	JTextField jt1=new JTextField();
    	JPasswordField jt2=new JPasswordField ();
    	public login() {
    		//jt2.setEchoChar((char)0);//密码可视
    		jt1.setBounds(90, 48, 180, 25);
    		jt2.setBounds(90, 98, 180, 25);
    		jl1.setBounds(44, 42, 70, 35);
    		jl2.setBounds(44, 92, 70, 35);
    		jb1.setBounds(60, 150, 70, 35);
    		jb2.setBounds(190, 150, 70, 35);
    		this.add(jb1);this.add(jl1);this.add(jl2);this.add(jt1);this.add(jt2);this.add(jb2);
    		jb1.addActionListener(this);
    		jb2.addActionListener(this);
    		this.setTitle("login");
    		this.setSize(350,250);
    		this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); 
    		this.setLocationRelativeTo(null); 
    		this.setLayout(null);
    		this.setResizable(false);
    		this.setVisible(true); 
    	}
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		new login();
    	}
    	@Override
    	public void actionPerformed(ActionEvent e1) {
    		// TODO Auto-generated method stub
    		if(e1.getSource()==jb1) {
    			if(jt1.getText().equals("")||jt2.getText().equals("")) {
    				JOptionPane.showMessageDialog(null, "账号或密码不能为空", "警告",JOptionPane.ERROR_MESSAGE);
    			}
    			else {
    				 Connection conn = null;
    			     Statement stmt = null;
    			      try {
    			    	  Class.forName(JDBC_DRIVER);
    			    	  conn = DriverManager.getConnection(DB_URL,USER,PASS);
    			    	  stmt = conn.createStatement();
    			    	  String sql;
    			            sql = "SELECT * FROM login";
    			            ResultSet rs = stmt.executeQuery(sql);
    			            int pd=0;
    			            while(rs.next()){
    			                // 通过字段检索
    			               String id  = rs.getString("id");
    			                String password = rs.getString("password");
    			                if(id.equals(jt1.getText())&&password.equals(jt2.getText())) {
    			                	JOptionPane.showMessageDialog(null, "账号密码正确,登陆成功!", "提示",JOptionPane.INFORMATION_MESSAGE );
    			                	pd=1;
    			                	new menu(id);dispose();//页面跳转
    			                	break;
    			                }              
    			            }
    			            if(pd==0) {JOptionPane.showMessageDialog(null, "账号或密码错误", "警告",JOptionPane.ERROR_MESSAGE);}
    			            // 完成后关闭
    			            rs.close();
    			            stmt.close();
    			            conn.close();
    			      }catch(SQLException se){
    			            // 处理 JDBC 错误
    			            se.printStackTrace();
    			        }catch(Exception e){
    			            // 处理 Class.forName 错误
    			            e.printStackTrace();
    			        }finally{
    			            // 关闭资源
    			            try{
    			                if(stmt!=null) stmt.close();
    			            }catch(SQLException se2){
    			            }// 什么都不做
    			            try{
    			                if(conn!=null) conn.close();
    			            }catch(SQLException se){
    			                se.printStackTrace();
    			            }
    			        }
    			}
    		}
    		else { new zhuce();dispose();}
    	}
    }
    

    界面截图

    在这里插入图片描述

    注册界面

    注册界面与之前的代码相比没有做太大的改变。
    代码如下(注:dispose()的作用是关闭当前的界面)

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import javax.swing.*;
    public class zhuce extends JFrame implements ActionListener{
    	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    	static final String DB_URL = "jdbc:mysql://localhost:3306/message";
    	static final String USER = "root";
        static final String PASS = "123456";
    	JButton jb1=new JButton("确定");
    	JButton jb2=new JButton("返回");
    	JLabel jl1=new JLabel("账号:");
    	JLabel jl2=new JLabel("密码:");
    	JLabel jl3=new JLabel("确认密码:");
    	JTextField jt1=new JTextField();
    	JTextField jt2=new JTextField();
    	JTextField jt3=new JTextField();
    	public zhuce() {
    		this.add(jb1);this.add(jb2);
    		this.add(jl1);this.add(jl2);this.add(jl3);
    		this.add(jt1);this.add(jt2);this.add(jt3);
    		jt1.setBounds(90, 18, 180, 25);
    		jt2.setBounds(90, 68, 180, 25);
    		jt3.setBounds(90, 118, 180, 25);
    		jl1.setBounds(44, 12, 70, 35);
    		jl2.setBounds(44, 62, 70, 35);
    		jl3.setBounds(30, 112, 70, 35);
    		jb1.setBounds(60, 160, 70, 35);
    		jb2.setBounds(190, 160, 70, 35);
    		jb1.addActionListener(this);
    		jb2.addActionListener(this);
    		this.setTitle("账号注册");
    		this.setSize(350,250);
    		this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); 
    		this.setLocationRelativeTo(null); 
    		this.setLayout(null);
    		this.setResizable(false);
    		this.setVisible(true); 
    	}
    	@Override
    	public void actionPerformed(ActionEvent e1) {
    		// TODO Auto-generated method stub
    		if(e1.getSource()==jb1) {
    			if(jt1.getText().length()==0) {JOptionPane.showMessageDialog(null, "账号不能为空", "警告",JOptionPane.ERROR_MESSAGE);}
    			else if(jt2.getText().length()==0||jt3.getText().length()==0) {
    				JOptionPane.showMessageDialog(null, "密码不能为空!", "警告",JOptionPane.ERROR_MESSAGE);
    			}
    			else if(!jt2.getText().equals(jt3.getText())) {
    				JOptionPane.showMessageDialog(null, "两次密码不相同,请重新输入!", "警告",JOptionPane.ERROR_MESSAGE);
    			}
    			else {
    				Connection conn = null;
    			      Statement stmt = null;
    			      PreparedStatement ps=null;
    			      try {
    			    	  Class.forName(JDBC_DRIVER);
    			    	  conn = DriverManager.getConnection(DB_URL,USER,PASS);
    			    	  stmt = conn.createStatement();
    			    	  String sql;
    			            sql = "SELECT * FROM login";
    			            ResultSet rs = stmt.executeQuery(sql);
    			            int pd=0;
    			            while(rs.next()){
    			                // 通过字段检索
    			               String id  = rs.getString("id");
    			               if(id.equals(jt1.getText())) {
    			                	JOptionPane.showMessageDialog(null, "账号已被注册,请重新输入!", "警告",JOptionPane.ERROR_MESSAGE);
    			                	pd=1;
    			                	break;
    			                }
    			            }
    			            if(pd==0) {
    			            	sql="INSERT INTO login VALUES(?,?)";
    			            	ps=conn.prepareStatement(sql);
    			            	ps.setString(1, jt1.getText());
    			            	ps.setString(2, jt2.getText());
    			            	if(ps.executeUpdate()!=0) {
    			            	JOptionPane.showMessageDialog(null, "账号注册成功!", "提示",JOptionPane.INFORMATION_MESSAGE );
    			            	new login();
    			    			dispose();
    			            	}
    			            	}
    			            // 完成后关闭
    			            rs.close();
    			            stmt.close();
    			            conn.close();
    			      }catch(SQLException se){
    			            // 处理 JDBC 错误
    			            se.printStackTrace();
    			        }catch(Exception e){
    			            // 处理 Class.forName 错误
    			            e.printStackTrace();
    			        }finally{
    			            // 关闭资源
    			            try{
    			                if(stmt!=null) stmt.close();
    			            }catch(SQLException se2){
    			            }// 什么都不做
    			            try{
    			                if(conn!=null) conn.close();
    			            }catch(SQLException se){
    			                se.printStackTrace();
    			            }
    			        }
    			}
    		}
    		else {
    			new login();
    			dispose();
    		}
    	}
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		new zhuce();
    	}
    }
    

    界面截图

    在这里插入图片描述

    菜单界面

    菜单界面做了传参处理,登录成功后会将用户名传到当前界面,并在Label中显示。
    代码如下(注:dispose()的作用是关闭当前的界面)

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class menu extends JFrame implements ActionListener{
    	JButton jb1=new JButton("修改密码");
    	JButton jb2=new JButton("切换用户");
    	JLabel jl1=new JLabel();
    	String user_id;
    	public menu(String id) {
    		user_id=id;
    		jl1.setText("用户:"+id);
    		this.add(jl1);
    		this.add(jb1);
    		this.add(jb2);
    		jl1.setBounds(120,20,100,30);
    		jb1.setBounds(110, 60, 100, 50);
    		jb2.setBounds(110, 130, 100, 50);
    		jb1.addActionListener(this);
    		jb2.addActionListener(this);
    		this.setTitle("菜单");
    		this.setSize(350,250);
    		this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); 
    		this.setLocationRelativeTo(null); 
    		this.setLayout(null);
    		this.setResizable(false);
    		this.setVisible(true); 
    	}
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		// TODO Auto-generated method stub
    		if(e.getSource()==jb1) {new password(user_id);dispose();}
    		else {new login();dispose();}
    	}
    }
    

    界面截图

    在这里插入图片描述

    修改密码界面

    修改密码界面做了传参处理,将用户名传到修改密码界面,并在TextField 里面显示,且那个TextField 设置为不可编辑。
    代码如下(注:dispose()的作用是关闭当前的界面)

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.*;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    public class password extends JFrame implements ActionListener{
    	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    	static final String DB_URL = "jdbc:mysql://localhost:3306/message";
    	static final String USER = "root";
        static final String PASS = "123456";
    	JButton jb1=new JButton("确定");
    	JButton jb2=new JButton("返回");
    	JLabel jl1=new JLabel("账号:");
    	JLabel jl2=new JLabel("原密码:");
    	JLabel jl3=new JLabel("新密码:");
    	JLabel jl4=new JLabel("确认密码:");
    	JTextField jt1=new JTextField();
    	JTextField jt2=new JTextField();
    	JTextField jt3=new JTextField();
    	JTextField jt4=new JTextField();
    	String user_id;
    	public password(String id) {
    		user_id=id;
    		//添加组件
    		this.add(jb1);this.add(jb2);
    		this.add(jt1);this.add(jt2);this.add(jt3);this.add(jt4);
    		this.add(jl1);this.add(jl2);this.add(jl3);this.add(jl4);
    		//设置组件位置和大小
    		jb1.setBounds(80, 250, 70, 35);
    		jb2.setBounds(180, 250, 70, 35);
    		jt1.setBounds(105, 48, 180, 25);
    		jt2.setBounds(105, 98, 180, 25);
    		jt3.setBounds(105, 148, 180, 25);
    		jt4.setBounds(105, 198, 180, 25);
    		jl1.setBounds(70, 42, 70, 35);
    		jl2.setBounds(57, 92, 70, 35);
    		jl3.setBounds(57, 142, 70, 35);
    		jl4.setBounds(44, 192, 70, 35);
    		jt1.setText(user_id);
    		jt1.setEditable(false);
    		jb1.addActionListener(this);
    		jb2.addActionListener(this);
    		//设置窗口属性
    		this.setTitle("修改密码");
    		this.setSize(350,350);
    		this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); 
    		this.setLocationRelativeTo(null); 
    		this.setLayout(null);
    		this.setResizable(false);
    		this.setVisible(true); 
    	}
    	@Override
    	public void actionPerformed(ActionEvent e1) {
    		// TODO Auto-generated method stub
    		if(e1.getSource()==jb1) {
    			if(jt1.getText().equals("")||jt2.getText().equals("")) {
    				JOptionPane.showMessageDialog(null, "账号或原密码不能为空", "警告",JOptionPane.ERROR_MESSAGE);
    			}
    			else if(jt3.getText().equals("")) {
    				JOptionPane.showMessageDialog(null, "请输入新的密码", "警告",JOptionPane.ERROR_MESSAGE);
    			}
    			else if(jt4.getText().equals("")) {
    				JOptionPane.showMessageDialog(null, "请确认新的密码", "警告",JOptionPane.ERROR_MESSAGE);
    			}
    			else if(!jt3.getText().equals(jt4.getText())) {
    				JOptionPane.showMessageDialog(null, "两次密码不相同", "警告",JOptionPane.ERROR_MESSAGE);
    			}
    			else {
    				Connection conn = null;
    				Statement stmt = null;
    				PreparedStatement ps=null;
    				 try{
    			            Class.forName(JDBC_DRIVER);
    			            conn = DriverManager.getConnection(DB_URL,USER,PASS);
    			            stmt = conn.createStatement();
    			            String sql;
    			            sql = "SELECT * FROM login";//搜索login表
    			            ResultSet rs = stmt.executeQuery(sql);
    			            int pd=0;
    			            while(rs.next()){
    			                int id  = rs.getInt("id");//得到“id”列的值
    			                String password = rs.getString("password");//得到“password”列的值
    			                if(jt1.getText().equals(String.valueOf(id))) {
    			                	pd=1;
    			                	if(jt2.getText().equals(password)) {
    			                		 try{
    			                	            Class.forName(JDBC_DRIVER);
    			                	            conn = DriverManager.getConnection(DB_URL,USER,PASS);
    			                	            stmt = conn.createStatement();
    			                	            String sql1;
    			                	            sql1="UPDATE login SET password=? WHERE id=?";//向login表里修改数据
    			                	            ps=conn.prepareStatement(sql1);//修改数据预处理
    			                	            ps.setString(1, jt3.getText());
    			                	            ps.setString(2, String.valueOf(id));
    			                	        	ps.executeUpdate();//执行修改数据
    			                	            ps.close();
    			                	            stmt.close();
    			                	            conn.close();
    			                	        }catch(SQLException se){
    			                	            se.printStackTrace();
    			                	        }catch(Exception e){
    			                	            e.printStackTrace();
    			                	        }finally{
    			                	            try{
    			                	                if(stmt!=null) stmt.close();
    			                	            }catch(SQLException se2){
    			                	            }
    			                	            try{
    			                	                if(conn!=null) conn.close();
    			                	            }catch(SQLException se){
    			                	                se.printStackTrace();
    			                	            }
    			                	        }
    			                		 JOptionPane.showMessageDialog(null, "密码修改成功!", "提示",JOptionPane.INFORMATION_MESSAGE );
    			                		 new menu(user_id);dispose();
    			                	}
    			                	else {
    			                		JOptionPane.showMessageDialog(null, "原密码输入错误,请重输", "警告",JOptionPane.ERROR_MESSAGE);
    			                	}
    			                	break;
    			                }
    			                
    			            }
    			            if(pd==0) {JOptionPane.showMessageDialog(null, "账号不存在,请重输", "警告",JOptionPane.ERROR_MESSAGE);}
    			            rs.close();
    			            stmt.close();
    			            conn.close();
    			        }catch(SQLException se){
    			            se.printStackTrace();
    			        }catch(Exception e){
    			            e.printStackTrace();
    			        }finally{
    			            try{
    			                if(stmt!=null) stmt.close();
    			            }catch(SQLException se2){
    			            }
    			            try{
    			                if(conn!=null) conn.close();
    			            }catch(SQLException se){
    			                se.printStackTrace();
    			            }
    			        }
    			}
    		}
    		else {new menu(user_id);dispose();}
    	}
    }
    

    界面截图

    在这里插入图片描述

    如有错误
    欢迎指出

    附:
    java对mysql的简单操作——增加数据
    java对mysql的简单操作——删除数据
    java对mysql的简单操作——修改数据
    java连接mysql5.1教程(查询数据)
    下一篇:用JAVA制作小游戏——推箱子(一)

    文件下载链接:

    csdn下载链接:点击此处
    百度网盘下载链接:点击此处 密码:ird3

    展开全文
  • java源码包---java 源码 大量 实例

    千次下载 热门讨论 2013-04-18 23:15:26
    发送消息,同时对文本进行少量修改,发送end-of-messages消息,最后关闭连接。 Tcp服务端与客户端的JAVA实例源代码 2个目标文件 摘要:Java源码,文件操作,TCP,服务器  Tcp服务端与客户端的JAVA实例源代码,一个简单...
  • 第一次点击修改,能获取到列表选中行数据的ID,弹窗正常,然后关闭弹窗,什么都不动再次点击修改,却获取不到选中行的ID了,获取到的ID居然是table的id,之后再怎么切换选中的行数据,获取的ID都变成table 的ID,...
  • java源码包2

    千次下载 热门讨论 2013-04-20 11:28:17
    发送消息,同时对文本进行少量修改,发送end-of-messages消息,最后关闭连接。 Tcp服务端与客户端的JAVA实例源代码 2个目标文件 摘要:Java源码,文件操作,TCP,服务器  Tcp服务端与客户端的JAVA实例源代码,一个...
  • java源码包3

    千次下载 热门讨论 2013-04-20 11:30:13
    发送消息,同时对文本进行少量修改,发送end-of-messages消息,最后关闭连接。 Tcp服务端与客户端的JAVA实例源代码 2个目标文件 摘要:Java源码,文件操作,TCP,服务器  Tcp服务端与客户端的JAVA实例源代码,一个...
  • java源码包4

    千次下载 热门讨论 2013-04-20 11:31:44
    发送消息,同时对文本进行少量修改,发送end-of-messages消息,最后关闭连接。 Tcp服务端与客户端的JAVA实例源代码 2个目标文件 摘要:Java源码,文件操作,TCP,服务器  Tcp服务端与客户端的JAVA实例源代码,一个...
  • 有时候在编辑页面用户做修改后,可能会有刷新、关闭等误操作造成当前页面信息的丢失, 何不先提醒一下用户呢?实例代码如下: <!DOCTYPE ...
  • java面试题

    2018-04-27 19:55:38
    游标是对查询出来的结果集作为一个单元来有效的处理,可以对结果集的当前行做修改。 select执行顺序? 答:from where group by having select order by Collection和Collections的区别? 答:Collection是集合...
  • JAVA上百实例源码以及开源项目

    千次下载 热门讨论 2016-01-03 17:37:40
    发送消息,同时对文本进行少量修改,发送end-of-messages消息,最后关闭连接。 Tcp服务端与客户端的JAVA实例源代码 2个目标文件 摘要:Java源码,文件操作,TCP,服务器  Tcp服务端与客户端的JAVA实例源代码,一个简单...
  • 发送消息,同时对文本进行少量修改,发送end-of-messages消息,最后关闭连接。 Tcp服务端与客户端的JAVA实例源代码 2个目标文件 摘要:Java源码,文件操作,TCP,服务器 Tcp服务端与客户端的JAVA实例源代码,一个简单的...
  • 发送消息,同时对文本进行少量修改,发送end-of-messages消息,最后关闭连接。 Tcp服务端与客户端的JAVA实例源代码 2个目标文件 摘要:Java源码,文件操作,TCP,服务器 Tcp服务端与客户端的JAVA实例源代码,一个简单的...
  • 发送消息,同时对文本进行少量修改,发送end-of-messages消息,最后关闭连接。 Tcp服务端与客户端的JAVA实例源代码 2个目标文件 摘要:Java源码,文件操作,TCP,服务器 Tcp服务端与客户端的JAVA实例源代码,一个简单的...
  • java 面试题 总结

    2009-09-16 08:45:34
    java.lang.String类是final类型的,因此不可以继承这个类、不能修改这个类。为了提高效率节省空间,我们应该用StringBuffer类 3、int 和 Integer 有什么区别 Java 提供两种不同的类型:引用类型和原始类型(或内置...
  • Ctrl+W 关闭当前Editer Ctrl+K 参照选中的Word快速定位到下一个 Ctrl+E 快速显示当前Editer的下拉列表(如果当前页面没有显示的用黑体表示) Ctrl+/(小键盘) 折叠当前类中的所有代码 Ctrl+×(小键盘) 展开当前类中的...
  • jsr80 java 访问 usb

    2015-02-14 08:52:01
    打印本页面用电子邮件发送本页面新浪微博人人网腾讯微博搜狐微博网易微博DiggFacebookTwitterDeliciousLinked In developerWorks 中国技术主题Java technology文档库 在 Java 应用程序中访问 USB 设备 介绍 USB、...
  • java写的记事本源代码

    2017-11-19 17:07:17
    在光标选中的内容里修改当前时间 3.格式(O) 可以通过点击菜单或快捷键(alt + O)打开菜单页 3.1自动换行(W) 菜单内点击或助记符W 选中后,文本会自动换行,且不能点击查看状态栏和转到菜单 3.2字体(F...
  • 由于当前手机都可以开启旋转屏幕功能,这导致了本应用在启动页面的时候,如果手机横向放置的话,页面会先横屏后竖屏。 在网上找了很久,有让修改framework设置的,(我不会)!还有让关闭重力感应的(没试)。 直到...
  • MyEclipse 6 Java 开发中文教程(完整版)

    热门讨论 2012-11-08 15:32:34
    3.2.18 查看当前类被哪些类引用...... 57 3.2.19 设置编辑器字体,颜色和显示行号..... 57 3.2.20 Link文件..... 58 3.2.21 安装插件..... 59 3.2.22 获取帮助和阅读帮助文档...... 59 3.2.23 CVS团队源代码管理...
  • Java项目开发实例自学手册

    热门讨论 2009-04-30 22:02:59
    1.15.2 关闭网站后session没有被注销 49 第2章 博客网站 50 2.1 概述 51 2.2 系统分析 51 2.2.1 需求分析 51 2.2.2 可行性分析 51 2.3 总体设计 51 2.3.1 项目规划 51 2.3.2 系统功能结构图 52 ...
  • 3.2.18查看当前类被哪些类引用 63 3.2.19设置编辑器字体,颜色和显示行号 63 3.2.20 Link文件 64 3.2.21安装插件 65 3.2.22获取帮助和阅读帮助文档 65 3.2.23 CVS团队源代码管理(在线阅读) 66 3.2.24 修改文件的...
  • a.pageContext:当前页面有效,页面跳转后失效 b.resquest:同一次请求有效,若请求转发方式修改为重定向(要进行两次请求)则无效 c.session:同一次会话有效,无论页面的跳转方式是请求转发还是重定向,关闭或切换...
  •  java.lang.String类是final类型的,因此不可以继承这个类、不能修改这个类。为了提高效率节省空间,我们应该用StringBuffer类 6、int 和 Integer 有什么区别  Java 提供两种不同的类型:引用类型和原始类型(或...
  • java-servlet-api.doc

    2009-10-13 19:34:17
    当Servlet引擎决定卸载一个Servlet时(例如,如果这个引擎被关闭或者需要让资源),这个引擎必须允许Servlet释放正在使用的资源并存储有关资料。为了完成以上工作,引擎会调用Servlet的destroy()方法。 在卸载一个...

空空如也

空空如也

1 2 3 4 5 6
收藏数 117
精华内容 46
关键字:

java当前修改页面关闭

java 订阅