Chapter 4: Creating a Printing Application


The Java Communication API (JCA) supports the javax.comm package. This package enables you to use the CommPortIdentifier and CommPort classes to detect the printer port. The CommPortIdentifier class provides a list of the ports available on your computer and the CommPort class opens a selected port for input/output operations.

This chapter explains how to develop a Printing application that uses the javax.comm package to select the printer port and print the text in a document. In addition, the application allows an end user to select and change the font and the color of the text in the document.

Architecture of the Printing Application

An end user can use the Printing application to list the ports on a computer. The end user can select the printer port, and open and print any text document. The end user can also change the font and the color of selected text in the document.

The Port Communication application uses the following files:

  • CommPrinting.java: Creates the user interface of the Printing application. This is the main file of the application.

  • ColorChoose.java: Enables the end user to use the Printing application to select the color of the text in the document to be printed.

  • FontChoose.java: Enables the end user to use the Printing application to select the font of the text in the document to be printed.

  • PortChoice.java: Lists the ports on a computer and enables the end user to select the port to which the printer is connected.

  • PrintComponent_Class.java: Specifies print setup properties and prints the text in the document that is currently open in the Printing application.

Figure 4-1 shows the architecture of the Printing application:

click to expand: this figure shows the various files used in the printing application and the sequence in which they are used.
Figure 4-1: Architecture of the Printing Application

In the Printing application, the CommPrinting.java file displays a user interface that consists of a menu bar and an edit pane. The various menu options on the menu bar enable an end user to specify the color and the font of the text in the document to be printed.

The CommPrinting.java file invokes:

  • The ColorChoose.java file when the end user selects the Color menu item from the Color menu.

  • The FontChoose.java file when the end user selects the Font menu option from the Font menu of the Printing application.

  • The PortChoice.java file when the end user selects the Choose COM Port to Print menu option from the File menu.

  • The PrintComponent_Class file to print the text in the document using the Printing application.




Developing Applications Using JCA
Developing Applications Using JCA
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 43

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