if (numCols != 132) { if (config.getStringProperty("print.portWidth").length() != 0 && config.getStringProperty("print.portHeight").length() != 0 && config.getStringProperty("print.portImageWidth").length() != 0 && config.getStringProperty("print.portImageHeight").length() != 0 && config.getStringProperty("print.portImage.X").length() != 0 && config.getStringProperty("print.portImage.Y").length() != 0) {  Paper paper = pf.getPaper();  paper.setSize( Double.parseDouble(config.getStringProperty("print.portWidth")), Double.parseDouble(config.getStringProperty("print.portHeight")));  paper.setImageableArea( Double.parseDouble(config.getStringProperty("print.portImage.X")), Double.parseDouble(config.getStringProperty("print.portImage.Y")), Double.parseDouble(config.getStringProperty("print.portImageWidth")), Double.parseDouble(config.getStringProperty("print.portImageHeight"))); pf.setPaper(paper); } } else {  if (config.getStringProperty("print.landWidth").length() != 0 && config.getStringProperty("print.landHeight").length() != 0 && config.getStringProperty("print.landImageWidth").length() != 0 && config.getStringProperty("print.landImageHeight").length() != 0 && config.getStringProperty("print.landImage.X").length() != 0 && config.getStringProperty("print.landImage.Y").length() != 0) {  Paper paper = pf.getPaper();  paper.setSize( Double.parseDouble(config.getStringProperty("print.landWidth")), Double.parseDouble(config.getStringProperty("print.landHeight")));  paper.setImageableArea( Double.parseDouble(config.getStringProperty("print.landImage.X")), Double.parseDouble(config.getStringProperty("print.landImage.Y")), Double.parseDouble(config.getStringProperty("print.landImageWidth")), Double.parseDouble(config.getStringProperty("print.landImageHeight"))); } }
   public void run () {// Toolkit tk = Toolkit.getDefaultToolkit();//int [][] range = new int[][] {//new int[] { 1, 1 }//};// JobAttributes jobAttributes = new JobAttributes(1, JobAttributes.DefaultSelectionType.ALL, JobAttributes.DestinationType.PRINTER, JobAttributes.DialogType.NONE, "file", 1, 1, JobAttributes.MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES, range, "HP LaserJet", JobAttributes.SidesType.ONE_SIDED);//PrintJob job = tk.getPrintJob(null, "Print", jobAttributes, null);//if (job != null) {      //--- Create a printerJob object      PrinterJob printJob = PrinterJob.getPrinterJob ();      printJob.setJobName("tn5250j");      // will have to remember this for the next time.      //   Always set a page format before call setPrintable to      //   set the orientation.      PageFormat pf = printJob.defaultPage();      if (numCols == 132)         pf.setOrientation(PageFormat.LANDSCAPE);      else         pf.setOrientation(PageFormat.PORTRAIT);      //--- Set the printable class to this one since we      //--- are implementing the Printable interface      printJob.setPrintable (this,pf);      // set the cursor back      session.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));      //--- Show a print dialog to the user. If the user      //--- clicks the print button, then print, otherwise      //--- cancel the print job      if (printJob.printDialog()) {         try {            // we do this because of loosing focus with jdk 1.4.0            session.requestFocus();            printJob.print();         } catch (Exception PrintException) {            PrintException.printStackTrace();         }      }      else {         // we do this because of loosing focus with jdk 1.4.0         session.requestFocus();      }      session = null;      int len = screen.length;      for (int x = 0; x < len; x++) {         screen[x] = null;      }      screen = null;   }