Chapter 5: Creating a Printer Management Application


The Java New Input/Output (NIO) API provides the java.nio, java.nio.channels, and java.awt.print packages, which you can use to perform various printer management functions. The java.nio package provides two classes, ByteBuffer and CharBuffer. You can use these classes to buffer a file. To read and write text and image files, you can use two classes provided by java.nio.channels, File and FileChannels. The java.awt.print package provides the PrinterJob and PageFormat classes to specify the properties of a file and print it. You can also use this package to manage the printers connected on the network.

This chapter describes how to develop a Printer Management application using the java.nio, java.nio.channels, and java.awt.print packages. It also explains how to read, write, buffer, format, and print text and image files. The application manages the printers that are connected to the computers that have Windows operating system.

Architecture of the Printer Management Application

The Printer Management application provides an interface that allows end users to create a book, add a document to the book, specify the document page setup, and simultaneously print the required number of copies of that book. The book interface also allows end users to customize the print settings and use the application to manage the network printers. The application provides a Print dialog box that displays the status of the printer.

The Printer Management application uses the following files:

  • PrintFile.java : Creates a user interface for the Printer Management application. This class also allows the end user to browse and open a file.

  • CreateBookInterface.java : Creates a book interface that helps the end user to add documents that are to be printed in a book.

  • PrintComp.java : Creates the Print dialog box to print the currently open document.

Figure 5-1 shows the architecture of the Printer Management application:

click to expand: this figure shows the files that the printer management application uses and the sequence in which it uses them.
Figure 5-1: Architecture of the Printer Management Application

The PrintFile.java file is the main class of the Printer Management application. The File menu of the PrintFile.java file allows end users to open a document, specify its page setup, and print it. If they select the File-> Print->Print Default or File->Page Setup & Print menu item, the PrintFile.java file calls the PrintComp.java file, which prints the currently open text or image file.

If end users select the File-> Print Custom menu item, the PrintFile.java file calls the CreateBookInterface.java file, which creates a book that can be printed. End users can specify the page format and the number of copies of each page they want to print. All the pages added to the book can be printed using one print command.




Java InstantCode. Developing Applications Using Java NIO
Java InstantCode. Developing Applications Using Java NIO
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 55

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net