1 package sample; 2 3 import java.awt.*; 4 import java.awt.print.*; 5 import com.qoppa.pdfPrinter.PDFPrinterJob; 6 7 12 public class Sample extends javax.swing.JFrame implements Printable 13 { 14 15 class IvjEventHandler implements java.awt.event.ActionListener { 16 public void actionPerformed(java.awt.event.ActionEvent e) { 17 if (e.getSource() == Sample.this.getjbPrintPanel()) 18 connEtoC1(e); 19 }; 20 }; 21 IvjEventHandler ivjEventHandler = new IvjEventHandler(); 22 private javax.swing.JButton ivjjbPrintPanel = null; 23 private javax.swing.JButton ivjJButton1 = null; 24 private javax.swing.JCheckBox ivjJCheckBox1 = null; 25 private javax.swing.JPanel ivjJFrameContentPane = null; 26 private javax.swing.JLabel ivjJLabel1 = null; 27 private javax.swing.JPanel ivjjpPanel = null; 28 private javax.swing.JRadioButton ivjJRadioButton1 = null; 29 private javax.swing.JTextField ivjJTextField1 = null; 30 33 public Sample() { 34 super(); 35 initialize(); 36 } 37 41 public Sample(String title) { 42 super(title); 43 } 44 48 49 private void connEtoC1(java.awt.event.ActionEvent arg1) { 50 try { 51 this.PrintPanel(arg1); 54 } catch (java.lang.Throwable ivjExc) { 57 handleException(ivjExc); 60 } 61 } 62 66 67 private javax.swing.JButton getjbPrintPanel() { 68 if (ivjjbPrintPanel == null) { 69 try { 70 ivjjbPrintPanel = new javax.swing.JButton (); 71 ivjjbPrintPanel.setName("jbPrintPanel"); 72 ivjjbPrintPanel.setText("Print Panel"); 73 ivjjbPrintPanel.setBounds(137, 191, 105, 25); 74 } catch (java.lang.Throwable ivjExc) { 77 handleException(ivjExc); 80 } 81 } 82 return ivjjbPrintPanel; 83 } 84 88 89 private javax.swing.JButton getJButton1() { 90 if (ivjJButton1 == null) { 91 try { 92 ivjJButton1 = new javax.swing.JButton (); 93 ivjJButton1.setName("JButton1"); 94 ivjJButton1.setText("JButton1"); 95 ivjJButton1.setBounds(64, 20, 85, 25); 96 } catch (java.lang.Throwable ivjExc) { 99 handleException(ivjExc); 102 } 103 } 104 return ivjJButton1; 105 } 106 110 111 private javax.swing.JCheckBox getJCheckBox1() { 112 if (ivjJCheckBox1 == null) { 113 try { 114 ivjJCheckBox1 = new javax.swing.JCheckBox (); 115 ivjJCheckBox1.setName("JCheckBox1"); 116 ivjJCheckBox1.setText("JCheckBox1"); 117 ivjJCheckBox1.setBounds(64, 65, 97, 22); 118 } catch (java.lang.Throwable ivjExc) { 121 handleException(ivjExc); 124 } 125 } 126 return ivjJCheckBox1; 127 } 128 132 133 private javax.swing.JPanel getJFrameContentPane() { 134 if (ivjJFrameContentPane == null) { 135 try { 136 ivjJFrameContentPane = new javax.swing.JPanel (); 137 ivjJFrameContentPane.setName("JFrameContentPane"); 138 ivjJFrameContentPane.setLayout(null); 139 getJFrameContentPane().add(getjpPanel(), getjpPanel().getName()); 140 getJFrameContentPane().add(getjbPrintPanel(), getjbPrintPanel().getName()); 141 } catch (java.lang.Throwable ivjExc) { 144 handleException(ivjExc); 147 } 148 } 149 return ivjJFrameContentPane; 150 } 151 155 156 private javax.swing.JLabel getJLabel1() { 157 if (ivjJLabel1 == null) { 158 try { 159 ivjJLabel1 = new javax.swing.JLabel (); 160 ivjJLabel1.setName("JLabel1"); 161 ivjJLabel1.setText("JLabel1"); 162 ivjJLabel1.setBounds(213, 29, 89, 14); 163 } catch (java.lang.Throwable ivjExc) { 166 handleException(ivjExc); 169 } 170 } 171 return ivjJLabel1; 172 } 173 177 178 private javax.swing.JPanel getjpPanel() { 179 if (ivjjpPanel == null) { 180 try { 181 ivjjpPanel = new javax.swing.JPanel (); 182 ivjjpPanel.setName("jpPanel"); 183 ivjjpPanel.setBorder(new javax.swing.border.EtchedBorder ()); 184 ivjjpPanel.setLayout(null); 185 ivjjpPanel.setBounds(28, 26, 323, 152); 186 getjpPanel().add(getJButton1(), getJButton1().getName()); 187 getjpPanel().add(getJCheckBox1(), getJCheckBox1().getName()); 188 getjpPanel().add(getJRadioButton1(), getJRadioButton1().getName()); 189 getjpPanel().add(getJLabel1(), getJLabel1().getName()); 190 getjpPanel().add(getJTextField1(), getJTextField1().getName()); 191 } catch (java.lang.Throwable ivjExc) { 194 handleException(ivjExc); 197 } 198 } 199 return ivjjpPanel; 200 } 201 205 206 private javax.swing.JRadioButton getJRadioButton1() { 207 if (ivjJRadioButton1 == null) { 208 try { 209 ivjJRadioButton1 = new javax.swing.JRadioButton (); 210 ivjJRadioButton1.setName("JRadioButton1"); 211 ivjJRadioButton1.setText("JRadioButton1"); 212 ivjJRadioButton1.setBounds(64, 107, 108, 22); 213 } catch (java.lang.Throwable ivjExc) { 216 handleException(ivjExc); 219 } 220 } 221 return ivjJRadioButton1; 222 } 223 227 228 private javax.swing.JTextField getJTextField1() { 229 if (ivjJTextField1 == null) { 230 try { 231 ivjJTextField1 = new javax.swing.JTextField (); 232 ivjJTextField1.setName("JTextField1"); 233 ivjJTextField1.setText("TextField"); 234 ivjJTextField1.setBounds(213, 64, 89, 20); 235 } catch (java.lang.Throwable ivjExc) { 238 handleException(ivjExc); 241 } 242 } 243 return ivjJTextField1; 244 } 245 249 private void handleException(java.lang.Throwable exception) { 250 251 252 } 255 259 260 private void initConnections() throws java.lang.Exception { 261 getjbPrintPanel().addActionListener(ivjEventHandler); 264 } 265 268 269 private void initialize() { 270 try { 271 setName("Sample"); 274 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 275 setSize(426, 240); 276 setContentPane(getJFrameContentPane()); 277 initConnections(); 278 } catch (java.lang.Throwable ivjExc) { 279 handleException(ivjExc); 280 } 281 } 284 288 public static void main(java.lang.String [] args) { 289 try { 290 Sample aSample; 291 aSample = new Sample(); 292 aSample.addWindowListener(new java.awt.event.WindowAdapter () { 293 public void windowClosing(java.awt.event.WindowEvent e) { 294 System.exit(0); 295 }; 296 }); 297 aSample.show(); 298 java.awt.Insets insets = aSample.getInsets(); 299 aSample.setSize(aSample.getWidth() + insets.left + insets.right, aSample.getHeight() + insets.top + insets.bottom); 300 aSample.setVisible(true); 301 } catch (Throwable exception) { 302 System.err.println("Exception occurred in main() of javax.swing.JFrame"); 303 exception.printStackTrace(System.out); 304 } 305 } 306 314 public int print(Graphics g, PageFormat pf, int pageIndex) 315 { 316 if (pageIndex == 0) 317 { 318 getjpPanel().print (g); 319 return Printable.PAGE_EXISTS; 320 } 321 else 322 { 323 return Printable.NO_SUCH_PAGE; 324 } 325 } 326 329 public void PrintPanel (java.awt.event.ActionEvent actionEvent) 330 { 331 try 332 { 333 PrinterJob printerJob = PDFPrinterJob.getPrinterJob(); 334 335 printerJob.setPrintable (this); 336 printerJob.setCopies (2); 337 printerJob.printDialog (); 338 printerJob.print (); 339 } 340 catch (Throwable t) 341 { 342 javax.swing.JOptionPane.showMessageDialog (this, t.getMessage()); 343 } 344 } 345 } 346 | Popular Tags |