ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:17.36KB ,
资源ID:28333036      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/28333036.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java Swing嵌入浏览器.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java Swing嵌入浏览器.docx

1、Java Swing嵌入浏览器import java.awt.BorderLayout;import java.awt.Toolkit;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.RandomAccessFile;import .HttpURLConnection;import .URL;import java.util.Ar

2、rayList;import java.util.Arrays;import java.util.Date;import java.util.List;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.SwingUtilities;import mon.UIUtils;import chrriis.dj.nativeswing.swtimpl.NativeInterface;import pon

3、ents.JWebBrowser;import ponents.WebBrowserCommandEvent;import ponents.WebBrowserEvent;import ponents.WebBrowserListener;import ponents.WebBrowserNavigationEvent;import ponents.WebBrowserWindowOpeningEvent;import ponents.WebBrowserWindowWillOpenEvent;import com.jacob.activeX.ActiveXComponent;import .

4、ComThread;import .Dispatch;import .Variant;import com.mohe.utils.system.L;/* * 主窗体 * * author dxm * */public class MainFrame extends JFrame private static final long serialVersionUID = -6348199501339114346L; / 最后操作时间 public long lastTime = new Date().getTime(); / 浏览器窗体 private JWebBrowser webBrowser

5、 = null; private JLabel lbl = null; private JPanel panel = null; public int pageFlag = 1; /* * 构造器 */ public MainFrame() initData(); initGUI(); addListance(); private void initData() Toolkit toolkit = Toolkit.getDefaultToolkit(); this.setUndecorated(true); this.setDefaultCloseOperation(JFrame.EXIT_O

6、N_CLOSE); this.setSize(600, 500); this.setLocationRelativeTo(null); this.setSize(toolkit.getScreenSize(); this.setLocation(0, 0); webBrowser = new JWebBrowser(); webBrowser.navigate(Config.local + Config.index); webBrowser.setBarsVisible(false); webBrowser.setMenuBarVisible(false); webBrowser.setLoc

7、ationBarVisible(false); webBrowser.setButtonBarVisible(false); webBrowser.setStatusBarVisible(false); ImageIcon icon = new ImageIcon(System.getProperty(user.dir) + 城市.gif); File img = new File(System.getProperty(user.dir) + + Config.img); if (img.exists() icon = new ImageIcon(img.getAbsolutePath();

8、lbl = new JLabel(icon); panel = new JPanel(new BorderLayout(); private void initGUI() panel.add(webBrowser, BorderLayout.CENTER); this.setContentPane(panel); private void addListance() webBrowser.addWebBrowserListener(new WebBrowserListener() Override public void windowWillOpen(WebBrowserWindowWillO

9、penEvent arg0) lastTime = new Date().getTime(); L.info(_ windowWillOpen); Override public void windowOpening(WebBrowserWindowOpeningEvent arg0) lastTime = new Date().getTime(); L.info(_ windowOpening); Override public void windowClosing(WebBrowserEvent arg0) lastTime = new Date().getTime(); L.info(_

10、 windowClosing); Override public void titleChanged(WebBrowserEvent arg0) lastTime = new Date().getTime(); L.info(_ titleChanged); Override public void statusChanged(WebBrowserEvent arg0) lastTime = new Date().getTime(); L.info(_ statusChanged); Override public void locationChanging(WebBrowserNavigat

11、ionEvent arg0) lastTime = new Date().getTime(); L.info(_ locationChanging); Override public void locationChanged(WebBrowserNavigationEvent arg0) lastTime = new Date().getTime(); L.info(_ locationChanged); / 判断当前页面等级 String locationURL = arg0.getNewResourceLocation(); int index = locationURL.indexOf(

12、pageFlag=); if (index != -1) pageFlag = Integer.parseInt(locationURL.substring(index + 9, index + 10); else pageFlag = 1; System.out.println(_ pageFlag: + pageFlag); / 判断下载文件进行打印 index = locationURL.indexOf(fileName=); System.out.println(_ file Index: + index); if (index != -1) String fs = locationU

13、RL.substring(index + 9); L.info(_ fileName = + fs); String fns = fs.split(,); try List flist = downNetFile(Arrays.asList(fns); doPrintDoc(flist); catch (IOException e) e.printStackTrace(); SwingUtilities.invokeLater(new Runnable() public void run() webBrowser.setVisible(false); webBrowser.setVisible

14、(true); webBrowser.updateUI(); webBrowser.repaint(); panel.updateUI(); panel.repaint(); panel.validate(); ); Override public void locationChangeCanceled(WebBrowserNavigationEvent arg0) lastTime = new Date().getTime(); L.info(_ locationChangeCanceled); Override public void loadingProgressChanged(WebB

15、rowserEvent arg0) lastTime = new Date().getTime(); L.info(_ loadingProgressChanged); Override public void commandReceived(WebBrowserCommandEvent arg0) lastTime = new Date().getTime(); L.info(_ commandReceived); ); lbl.addMouseListener(new MouseListener() Override public void mouseReleased(MouseEvent

16、 arg0) Override public void mousePressed(MouseEvent arg0) Override public void mouseExited(MouseEvent arg0) Override public void mouseEntered(MouseEvent arg0) Override public void mouseClicked(MouseEvent arg0) change(2); ); /* * 屏保切换 */ public void change(final int type) lastTime = new Date().getTim

17、e(); SwingUtilities.invokeLater(new Runnable() public void run() if (type = 1) / 二级,三级页面跳首页 if (pageFlag = 2 | pageFlag = 3) webBrowser.navigate(Config.local + Config.index); / else / webBrowser.setVisible(false); / panel.add(lbl, BorderLayout.CENTER); / else panel.remove(lbl); webBrowser.setVisible

18、(true); panel.validate(); ); /* * 下载网络文件 * * param nameList * throws IOException */ private List downNetFile(List nameList) throws IOException L.info(_ downNetFile1); if (null = nameList | nameList.isEmpty() return new ArrayList(); List flist = new ArrayList(); for (String name : nameList) L.info(_

19、downNetFile2); URL url = new URL(Config.local + /excel/ + name); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); / 设置请求信息 httpConnection.setRequestProperty(GET, /down.zip HTTP/1.1); / 设置接受信息 httpConnection.setRequestProperty(Accept, image/gif,image/x-xbitmap,application/

20、msword); / 设置连接信息 httpConnection.setRequestProperty(Connection, Keep-Alive); / 获得输入流 InputStream input = httpConnection.getInputStream(); / 创建随机文件 flist.add(new File(name); RandomAccessFile oSavedFile = new RandomAccessFile(name, rw); byte b = new byte1024; int nRead; / 从输入流中读入字节流,然后写到文件中 while (nRe

21、ad = input.read(b, 0, 1024) 0) oSavedFile.write(b, 0, nRead); input.close(); oSavedFile.close(); httpConnection.disconnect(); return flist; private void doPrintDoc(List fileList) if (null = fileList | fileList.isEmpty() return; / 初始化组件 ComThread.InitSTA(); L.info(_ start Print 1); for (File file : f

22、ileList) if (file = null | !file.exists() return; L.info(_ start Print 2 : + file.getAbsolutePath(); int index = file.getName().indexOf(.); String extName = file.getName().toUpperCase().substring(index + 1); String comApp = Word.Application; String property = Documents; if (extName.equals(DOC) | ext

23、Name.equals(DOCX) | extName.equals(WPS) comApp = Word.Application; property = Documents; else if (extName.equals(XLS) | extName.equals(XLSX) | extName.equals(ET) comApp = Excel.Application; property = Workbooks; else if (extName.equals(PPT) | extName.equals(PPTX) | extName.equals(DPS) comApp = Power

24、Point.Application; property = Presentations; L.info(_ start Print 3 : + comApp); ActiveXComponent axc = new ActiveXComponent(comApp); try if (!property.equals(Presentations) Dispatch.put(axc, Visible, new Variant(false); Dispatch document = axc.getProperty(property).toDispatch(); Dispatch doc = null

25、; if (property.equals(Presentations) doc = Dispatch.call(document, Open, file.getAbsolutePath(), true, true, false).toDispatch(); else doc = Dispatch.invoke(document, Open, Dispatch.Method, new Object file.getAbsolutePath() , new int1).toDispatch(); L.info(_ start Print 3 : + file.getAbsolutePath(); Dispatch.call(doc, PrintOut); Dispatch.call(doc, Close); if (!property.equals(Presentations) axc.invoke(Quit, new Variant ); catch (Exception e) e.printStackTrace(); finally comApp = ; property = ; ComThread.Release(); public static void main(String args)

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1