日期:2014-05-17 浏览次数:21027 次
1.import java.awt.BorderLayout; 2.import java.awt.Dimension; 3.import java.awt.FlowLayout; 4.import java.awt.image.BufferedImage; 5.import java.io.File; 6.import java.io.IOException; 7.import javax.imageio.ImageIO; 8.import javax.swing.JFrame; 9.import javax.swing.JPanel; 10.import javax.swing.SwingUtilities; 11.import chrriis.dj.nativeswing.swtimpl.NativeComponent; 12.import chrriis.dj.nativeswing.swtimpl.NativeInterface; 13.import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser; 14.import chrriis.dj.nativeswing.swtimpl.components.WebBrowserAdapter; 15.import chrriis.dj.nativeswing.swtimpl.components.WebBrowserEvent; 16.public class Main extends JPanel { 17. /** 18. * 19. */ 20. private static final long serialVersionUID = 1L; 21. // 行分隔符 22. final static public String LS = System.getProperty("line.separator", "\n"); 23. // 文件分割符 24. final static public String FS = System.getProperty("file.separator", "\\"); 25. //以javascript脚本获得网页全屏后大小 26. final static StringBuffer jsDimension; 27. 28. static { 29. jsDimension = new StringBuffer(); 30. jsDimension.append("var width = 0;").append(LS); 31. jsDimension.append("var height = 0;").append(LS); 32. jsDimension.append("if(document.documentElement) {").append(LS); 33. jsDimension.append( 34. " width = Math.max(width, document.documentElement.scrollWidth);") 35. .append(LS); 36. jsDimension.append( 37. " height = Math.max(height, document.documentElement.scrollHeight);") 38. .append(LS); 39. jsDimension.append("}").append(LS); 40. jsDimension.append("if(self.innerWidth) {").append(LS); 41. jsDimension.append(" width = Math.max(width, self.innerWidth);") 42. .append(LS); 43. jsDimension.append(" height = Math.max(height, self.innerHeight);") 44. .append(LS); 45. jsDimension.append("}").append(LS); 46. jsDimension.append("if(document.body.scrollWidth) {").append(LS); 47. jsDimension.append( 48. " width = Math.max(width, document.body.scrollWidth);") 49. .append(LS); 50. jsDimension.append( 51. " height = Math.max(height, document.body.scrollHeight);") 52. .append(LS); 53. jsDimension.append("}").append(LS); 54. jsDimension.append("return width + ':' + height;"); 55. } 56. //DJNativeSwing组件请于http://djproject.sourceforge.net/main/index.html下载 57. public Main(final String url, final int maxWidth, final int maxHeight) { 58. super(new BorderLayout()); 59. JPanel webBrowserPanel = new JPanel(new BorderLayout()); 60. final String fileName = System.currentTimeMillis() + ".jpg"; 61. final JWebBrowser webBrowser = new JWebBrowser(null); 62. webBrowser.setBarsVisi