Thursday, July 30, 2015
How to Check Printer Status Using Java
Open the Integrated Development Environment (IDE) program on your PC. Click 'File' and then 'Open' on the menu bar. Navigate to the Java application project file for which you want to enable print functions. Highlight the project file and click 'Open.'
Click 'File' or 'Create' on the menu tool bar. Scroll down to and click 'New/Class.' Wait for the IDE to load 'New Class' or 'Class' document window in the main project work area or screen. Click 'File/Save' on the menu bar. Save the class file as 'PrinterStatus.java.'
Enter the following code into the 'PrinterStatus.java' document window to define a new class object:public class PrinterStatus{public static void main(String[] args) { PrintService printer = PrintServiceLookup.lookupDefaultPrintService();AttributeSet att = printer.getAttributes();for (Attribute a : att.toArray()) {String attributeName;String attributeValue;attributeName = a.getName();attributeValue = att.get(a.getClass()).toString();System.out.println(attributeName + ' : ' + attributeValue);}}}
Click 'File' and then 'Save' on the menu tool bar. Close the 'PrinterStatus.java' class document window. Your Java web application can now process status requests for the main printer attached to the local PC.
Open another class or module from which to call, or initiate, printer status requests. Enter the following code at the point where the application should initiate the request: StatusofPrinterReport obj=new StatusofPrinterReport();obj.main()
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment