1 28 import java.awt.BorderLayout ; 29 import java.io.PrintWriter ; 30 import java.io.StringWriter ; 31 import java.net.URL ; 32 33 import javax.swing.JOptionPane ; 34 35 import net.sf.jasperreports.engine.JasperPrint; 36 import net.sf.jasperreports.engine.util.JRLoader; 37 38 39 43 public class EmbeddedViewerApplet extends javax.swing.JApplet  44 { 45 46 47 50 private JasperPrint jasperPrint = null; 51 52 53 54 public EmbeddedViewerApplet() 55 { 56 initComponents(); 57 } 58 59 60 63 public void init() 64 { 65 String url = getParameter("REPORT_URL"); 66 if (url != null) 67 { 68 try 69 { 70 jasperPrint = (JasperPrint)JRLoader.loadObject(new URL (getCodeBase(), url)); 71 if (jasperPrint != null) 72 { 73 JRViewerSimple viewer = new JRViewerSimple(jasperPrint); 74 this.pnlMain.add(viewer, BorderLayout.CENTER); 75 } 76 } 77 catch (Exception e) 78 { 79 StringWriter swriter = new StringWriter (); 80 PrintWriter pwriter = new PrintWriter (swriter); 81 e.printStackTrace(pwriter); 82 JOptionPane.showMessageDialog(this, swriter.toString()); 83 } 84 } 85 else 86 { 87 JOptionPane.showMessageDialog(this, "Source URL not specified"); 88 } 89 } 90 91 92 97 private void initComponents() { pnlMain = new javax.swing.JPanel (); 99 100 pnlMain.setLayout(new java.awt.BorderLayout ()); 101 102 getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER); 103 104 } 106 107 private javax.swing.JPanel pnlMain; 109 111 } 112
| Popular Tags
|