重点在于: 得到url都是在locationchanging 方法里获得的 所以 第一次弹窗得给JWebBrowser 添加监听 在监听里获得 第二个弹窗也添加监听 在监听里获得
package org.jivesoftware.pmsaas.sys.domain;
import java.awt.BorderLayout;
import java.util.Hashtable;
import java.util.Map;
import javax.swing.JPanel;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserCommandEvent;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserEvent;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserListener;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserNavigationEvent;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserWindowOpeningEvent;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserWindowWillOpenEvent;
/**
* 该类是一个浏览器类 也是面板类 该类中面板和浏览器整合为一体 ----也就是浏览器面板
* */
public class NetBrowser extends JPanel{
/**
*
*/
private static final long serialVersionUID = -679703553152283868L;
private JPanel webBrowserPanel;
public static Map<String,JWebBrowser>t_jwbrowsers=new Hashtable<String, JWebBrowser>();;
private static JWebBrowser webBrowser;
public NetBrowser(String url)
{
super(new BorderLayout());
webBrowserPanel = new JPanel(new BorderLayout());
webBrowser = new JWebBrowser();
/**
* native swing 官方API解释
* navigate
public boolean navigate(String resourceLocation)
Navigate to a resource, with its location specified as a URL or path.
Parameters:
resourceLocation - the URL or path.
Returns:
true if the navigation was successful.
* */
webBrowser.navigate(url);
webBrowser.setButtonBarVisible(false);
webBrowser.setMenuBarVisible(true);
webBrowser.setBarsVisible(false);
webBrowser.setStatusBarVisible(false);
webBrowser.addWebBrowserListener(new WebBrowserListener() {
@Override
public void windowWillOpen(WebBrowserWindowWillOpenEvent arg0) {
JWebBrowser jwb=arg0.getNewWebBrowser();
jwb.addWebBrowserListener(new WebBrowserListener() {
@Override
public void windowWillOpen(WebBrowserWindowWillOpenEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpening(WebBrowserWindowOpeningEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void titleChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void statusChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void locationChanging(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
String location=arg0.getNewResourceLocation();
System.out.println("二次弹出的窗口的url: "+location);
}
@Override
public void locationChanged(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void locationChangeCanceled(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void commandReceived(WebBrowserCommandEvent arg0) {
// TODO Auto-generated method stub
}
});
}
@Override
public void windowOpening(WebBrowserWindowOpeningEvent arg0) {
// JWebBrowser jwb=arg0.getNewWebBrowser();
// String location=jwb.getResourceLocation();
// System.out.println(location);
}
@Override
public void windowClosing(WebBrowserEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void titleChanged(WebBrowserEvent arg0) {
}
@Override
public void statusChanged(WebBrowserEvent arg0) {
}
@Override
public void locationChanging(WebBrowserNavigationEvent arg0) {
String location=arg0.getNewResourceLocation();
System.out.println("第一次窗口的页面跳转的url "+location);
}
@Override
public void locationChanged(WebBrowserNavigationEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void locationChangeCanceled(WebBrowserNavigationEvent arg0) {
}
@Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
}
@Override
public void commandReceived(WebBrowserCommandEvent arg0) {
}
});
//webBrowserPanel与webBrowser互相包含
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
add(webBrowserPanel, BorderLayout.CENTER);
t_jwbrowsers.put(url, webBrowser);
}
public static JWebBrowser getJWebBrowser(String url){
return t_jwbrowsers.get(url);
}
}