意思是你不能用 主GUI线程以外的线程来调用该方法。建议你用:SwingUtilities.invokeLater 来借助主GUI线程,通过回调的方式间接调用该方法。
解决方案 »
- 关于ajaxfileupload.js的问题
- 如何学好javaEE???
- 下面sql如何改为hql,谢谢!
- 多行数据提交到struts的ActionFrom的List属性中为什么得不到值?
- DWR实现文件下载功能
- jdom+xpath 的问题
- struts 问题
- ejb新手入门,生成helloworld.jar之后该做什么!
- 我用JB将application打包成.JAR运行有问题,把.jar解开后,用DOS窗口运行java -classpath ...没有问题,我的程序中应用了XML,这是怎么回
- EJB出现错误,那位指教一下如何配置文件?
- 求帮忙
- java上传图片到另一台服务器上,如何解决?
主GUI线程 不知道
毁掉方式 不知道从何下手 迷茫
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// SWT组件转Swing组件,不初始化父窗体将无法启动webBrowser
JFrame frame = new JFrame("以DJ组件保存指定网页截图");
frame.getContentPane().add(
new Jar3("http://www.baidu.com/", 1500, 900),
BorderLayout.CENTER);
frame.setSize(600, 500);
// 仅初始化,但不显示
frame.invalidate();
frame.pack();
frame.setVisible(false);
}
});
NativeInterface.runEventPump();
System.out.println("ok");
}new Jar3("http://www.baidu.com/", 1500, 900) 这里的参数是动态的如何在其他地方调用 main方法中的代码
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Jar3XML().shapshot();
new Jar3XML().shapshot();
}
}
但这个最终用在servlet上时怎么调用。主要是外头那个壳儿,用第二次就错,不用也错
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Jar3XML().shapshot();
new Jar3XML().shapshot();
}
}
JPanel webBrowserPanel = new JPanel(new BorderLayout());
final String fileName = System.currentTimeMillis() + ""
+ new Random().nextInt();
final JWebBrowser webBrowser = new JWebBrowser(null); webBrowser.setBarsVisible(false);
webBrowser.navigate(srcUrl); webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
add(webBrowserPanel, BorderLayout.CENTER); JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4)); webBrowser.addWebBrowserListener(new WebBrowserAdapter() { // 监听加载进度
public void loadingProgressChanged(WebBrowserEvent e) {
Servlet?!你在J2EE服务器上玩JFrame?这应该是不行的啊
另外就是,也许你还得研究下:JWebBrowser这个组件,自身是否允许同时使用多个?
头疼啊,JWebBrowser 这组件没说明没资料。。
就是放服务器上啊,就好像某些网站上的网页快照一样。servlet 请求很蛋疼啊,没有方法啊,没有方法啊~~public void service(HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() { public void run() {
Shapshot.shapshot();
try {
response.sendRedirect("ok.jsp");
} catch (IOException e) {
e.printStackTrace();
}
}
});
NativeInterface.runEventPump();
return;
}报同样的错不过谢谢了啊,今天搞了一天,这个问题还没解决
最后如果还没招,也许就的考虑换个做页面快照的组件了其实,搜索引擎的快照,并不保存图片,它只是稍微完整点下载了HTML和CSS的内容而已。
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {public void run() {
// TODO Auto-generated method stub
Shapshot.shapshot();
Shapshot.shapshot();
}
});
NativeInterface.runEventPump();
}这样不会报错,并且成功截取2次// Shapshot.shapshot();这个怎么能够调用!!!! 愁啊
servlet 中这样写
{
NativeInterface.open();
Shapshot.shapshot();
response.sendRedirect("ok.jsp");
NativeInterface.runEventPump();
}
或者这样写
{
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Shapshot.shapshot();
try {
response.sendRedirect("ok.jsp");
return;
} catch (IOException e) {
e.printStackTrace();
}
}
});
NativeInterface.runEventPump();
}都是同一个错
Exception in thread "main" java.lang.IllegalStateException: runEventPump was already called and can only be called once (the first call should be at the end of the main method)!
经测试,JWebBrowaser确实是异步的,求大神给点方向……另外这方法写出来就是用来调用的啊!!总不至于总在main里写线程吧~~~真心搞不懂网上找遍了,遇到这问题的貌似都没解决,剩下的就是没遇到这问题的。。
public static synchronized 返回值 takeSnapshot() {
NativeInterface.open();
try {
return Shapshot.shapshot();
} finally {
NativeInterface.runEventPump();
}
}
main中这样写 NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() { public void run() {
Shapshot.shapshot("http://www.baidu.com", 1);
}
});
NativeInterface.runEventPump();
servlet中这样写 srcUrl = request.getParameter("srcurl");
method = Integer.parseInt(request.getParameter("method"));
HttpSession session = request.getSession();
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
rePath = Shapshot.shapshot(srcUrl, method);
}
});
// NativeInterface.runEventPump();
session.setAttribute("repath", rePath);
response.sendRedirect("ok.jsp");