الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

أمر الى الطابعه(print)

مغلق
بدأه الفكر في 5 يونيو 2005 · 2 رد · 736 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

سلام عليكم

يبدو من العنوان مايتحاج شرح

يعني مثلا لو حبيت أطبع جمله موجوده في البرنامج أو من ملف أو من تكست

ماهو الكود؟

ولكم خالص الشكر والتحايا

تم تعديل هذه المشاركة بواسطة الفكر في 5 يونيو 2005 في 16:57

#2

الكود التالي يرسل أمر الى الطابعة لطباعة صورة أسمها nicePic.gif تتواجد بنفس مسار الكلاس:

import java.io.*;
import javax.print.*;
import javax.print.event.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;

class PrintStatus implements PrintJobListener {
  
  public void printDataTransferCompleted(PrintJobEvent pje) {
 	 System.out.println("Data delivered to printer succesfully ...");
  }
  public void printJobCanceled(PrintJobEvent pje) {
  System.out.println("The print job has been cancelled ..."); 	 
  }
  public void printJobCompleted(PrintJobEvent pje) {
 	 System.out.println("The print job completed successfully ...");
  }
  public void printJobFailed(PrintJobEvent pje) {
 	 System.out.println("The document failed to print ..");
  }
  public void printJobNoMoreEvents(PrintJobEvent pje) {
 	 System.out.println("No more events to deliver ...");
  }
  public void printJobRequiresAttention(PrintJobEvent pje) {
 	 System.out.println("Some thing terrible happend which requires attention ...");
  }
}

public class JPSPrint {

	public static void main(String args[]) throws FileNotFoundException{

	PrintStatus status = new PrintStatus();

	/*Create the DocFlavor for GIF */
	DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
	/* Create an attribute set comprising of the print instructions*/
	PrintRequestAttributeSet attribSet = new HashPrintRequestAttributeSet();
	attribSet.add(new Copies(1));
	attribSet.add(MediaSizeName.ISO_A4);

	/* Locate print services, which can print a GIF in the manner specified */
	PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, attribSet);

	if (pservices.length > 0) {

  DocPrintJob job = pservices[0].createPrintJob();
  /* Adding a PrintStatus Listener */
  job.addPrintJobListener(status);	
  /* Create a Doc implementation to pass the print data */
  FileInputStream fInput = new FileInputStream("nicePic.gif");
  Doc doc = new SimpleDoc(fInput, flavor, null);

  /* Print the doc as specified */
  try {
 	 job.print(doc, attribSet);
  } 
  catch (PrintException e) { 
 	 System.err.println(e);
  }
	} 
	else 
  System.err.println("No suitable printers");
   }
}
#3

أخوي student

الله يعطيك الف عافيه تقبل تحياتي

هذا الموضوع مغلق.

مواضيع مشابهة