⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 docviewframe.java

📁 java调用ie浏览器demo源码,可以用在windows或者linux
💻 JAVA
字号:

import javax.swing.SwingUtilities;
import org.jdic.web.BrComponent;

/*
 * DocViewFrame.java
 *
 * Created on June 18, 2008, 12:34 PM
 */
import org.jdic.web.event.BrComponentEvent;
import org.jdic.web.event.BrComponentListener;



/**
 *
 * @author  uta
 */
public class DocViewFrame extends javax.swing.JFrame {

    /** Creates new form DocViewFrame */
    public DocViewFrame() {
        BrComponent.DESIGN_MODE = false;
        BrComponent.setDefaultPaintAlgorithm(BrComponent.PAINT_NATIVE);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        brView = new org.jdic.web.BrComponent();
        tbCommands = new javax.swing.JToolBar();
        btFlashGame = new javax.swing.JButton();
        btVideo = new javax.swing.JButton();
        btPDF = new javax.swing.JButton();
        btDisk = new javax.swing.JButton();
        btMSWord = new javax.swing.JButton();
        btMSExcel = new javax.swing.JButton();
        btMSOutlook = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Document Viewer");
        setName("main"); // NOI18N

        brView.setName("viewer"); // NOI18N

        javax.swing.GroupLayout brViewLayout = new javax.swing.GroupLayout(brView);
        brView.setLayout(brViewLayout);
        brViewLayout.setHorizontalGroup(
            brViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 397, Short.MAX_VALUE)
        );
        brViewLayout.setVerticalGroup(
            brViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 279, Short.MAX_VALUE)
        );

        getContentPane().add(brView, java.awt.BorderLayout.CENTER);

        tbCommands.setFloatable(false);
        tbCommands.setRollover(true);
        tbCommands.setMaximumSize(new java.awt.Dimension(10, 20));
        tbCommands.setMinimumSize(new java.awt.Dimension(10, 20));

        btFlashGame.setText("Flash Game");
        btFlashGame.setFocusable(false);
        btFlashGame.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btFlashGame.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btFlashGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btFlashGameActionPerformed(evt);
            }
        });
        tbCommands.add(btFlashGame);

        btVideo.setText("Video");
        btVideo.setFocusable(false);
        btVideo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btVideo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btVideo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btVideoActionPerformed(evt);
            }
        });
        tbCommands.add(btVideo);

        btPDF.setText("PDF Reader");
        btPDF.setFocusable(false);
        btPDF.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btPDF.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btPDF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPDFActionPerformed(evt);
            }
        });
        tbCommands.add(btPDF);

        btDisk.setText("Disk C:");
        btDisk.setFocusable(false);
        btDisk.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btDisk.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btDisk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDiskActionPerformed(evt);
            }
        });
        tbCommands.add(btDisk);

        btMSWord.setText("MS Word");
        btMSWord.setFocusable(false);
        btMSWord.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btMSWord.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btMSWord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMSWordActionPerformed(evt);
            }
        });
        tbCommands.add(btMSWord);

        btMSExcel.setText("MS Excel");
        btMSExcel.setFocusable(false);
        btMSExcel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btMSExcel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btMSExcel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMSExcelActionPerformed(evt);
            }
        });
        tbCommands.add(btMSExcel);

        btMSOutlook.setText("MS Outlook");
        btMSOutlook.setFocusable(false);
        btMSOutlook.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btMSOutlook.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btMSOutlook.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMSOutlookActionPerformed(evt);
            }
        });
        tbCommands.add(btMSOutlook);

        getContentPane().add(tbCommands, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btVideoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btVideoActionPerformed
    brView.setURL("");
    brView.addBrComponentListener( new BrComponentListener(){
            public String sync(BrComponentEvent e) {
                if(BrComponentEvent.DISPID_NAVIGATECOMPLETE2 == e.getID()){
                    brView.setHTML(
"<html><head></head><body style='border:none;margin: 0px 0px 0px 0px;' scroll='no' scrolling='no'>" + 
"<object style='margin: 0px 0px 0px 0px; width:100%; height:100%' " +
        "value='http://www.youtube.com/v/mlTKOsBOVMw&hl=en'>" + 
        "<param name='wmode' value='transparent'> " +
        "<embed style='margin: 0px 0px 0px 0px; width:100%; height:100%' src='http://www.youtube.com/v/mlTKOsBOVMw&hl=en' type='application/x-shockwave-flash' wmode='transparent'></embed>" +
"</object></body></html>"                        
                    );    
                    brView.removeBrComponentListener(this);
                }    
                return null;
            }
    });        
}//GEN-LAST:event_btVideoActionPerformed

private void btMSWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMSWordActionPerformed
    brView.setURL("http://www.aaopt.org/content/docs/course-abstractFAQs.doc");
}//GEN-LAST:event_btMSWordActionPerformed

private void btMSOutlookActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMSOutlookActionPerformed
    //http://weblogs.asp.net/mnissen/archive/2004/07/05/173364.aspx
    //http://www.outlookcode.com/d/OVCViewDemo.htm
    // typelib filename: OUTLCTL.DLL
    brView.setURL("");
    brView.addBrComponentListener( new BrComponentListener(){
            public String sync(BrComponentEvent e) {
                if(BrComponentEvent.DISPID_NAVIGATECOMPLETE2 == e.getID()){
                    brView.setHTML(
"<html><head></head><body style='border:none;margin: 0px 0px 0px 0px;' scroll='no' scrolling='no'>" + 
      "<object classid='CLSID:0006F063-0000-0000-C000-000000000046' " +
            "id='ViewCtlFolder' " +
            "width='100%' " +
            "height='100%' " +
            "codebase='http://activex.microsoft.com/activex/controls/office/outlctlx.CAB#ver=9,0,0,3203'>"+
       "<param name='Namespace' value='MAPI'>"+
       "<param name='Folder' value='Calendar'>"+
       "<param name='View' value='Day/Week/Month View With AutoPreview'>"+
       "<param name='Restriction' value=''>"+
       "<param name='DeferUpdate' value='0'>"+
"</object></body></html>"                        
                    );    
                    brView.removeBrComponentListener(this);
                }    
                return null;
            }
    });
}//GEN-LAST:event_btMSOutlookActionPerformed

private void btFlashGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFlashGameActionPerformed
    brView.setURL("");
    brView.addBrComponentListener( new BrComponentListener(){
            public String sync(BrComponentEvent e) {
                if(BrComponentEvent.DISPID_NAVIGATECOMPLETE2 == e.getID()){
                    brView.setHTML(
"<html><head></head><body style='border:none;margin: 0px 0px 0px 0px;' scroll='no' scrolling='no'>" + 
"<object style='margin: 0px 0px 0px 0px; width:100%; height:100%' classid='CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'> " +
"  <param name='movie' value='http://flashportal.ru/monstertruckcurfew.swfi'> " +
"  <param name='quality' value='high'> " +
"  <param name=bgcolor value='#00FF00'>" +
"</object></body></html>"                        
                    );    
                    brView.removeBrComponentListener(this);
                }    
                return null;
            }
    });

}//GEN-LAST:event_btFlashGameActionPerformed

private void btPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPDFActionPerformed
    brView.setURL("http://java.sun.com/developer/Books/j2ee/advancedprogramming/jni.pdf");    
}//GEN-LAST:event_btPDFActionPerformed

private void btDiskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDiskActionPerformed
    brView.setURL("c:/");
}//GEN-LAST:event_btDiskActionPerformed

private void btMSExcelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMSExcelActionPerformed
    brView.setURL("http://www.seomoz.org/user_files/top-100-domains/SEOmoz-Top-100-Most-Visited-Domains.xls");
}//GEN-LAST:event_btMSExcelActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DocViewFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdic.web.BrComponent brView;
    private javax.swing.JButton btDisk;
    private javax.swing.JButton btFlashGame;
    private javax.swing.JButton btMSExcel;
    private javax.swing.JButton btMSOutlook;
    private javax.swing.JButton btMSWord;
    private javax.swing.JButton btPDF;
    private javax.swing.JButton btVideo;
    private javax.swing.JToolBar tbCommands;
    // End of variables declaration//GEN-END:variables

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -