To test the Printer Management application:
Set the
set path=%path%;D:\j2sdk1.4.0_02\bin;
Set the classpath of the lib directory of J2SDK by executing the following command at the command prompt:
set classpath = %classpath%;d:\j2sdk1.4.0_02\lib;
Copy the PrintFile.java, PrintComp.java, and CreateBookInterface.java files to a folder on your computer. On the command prompt, use the cd command to move to that folder where you have
javac *.java
To run the Printer Management application, specify the following command at the command prompt:
java PrintFile
Click the Print Text tab in the
Select the File->Open command from the File menu of the Printer Management Application. Browse and open the text file that is to be printed using the
Figure 5-5:
Printer Management Application Window
Select the File->Page Setup & Print command. The Page Setup dialog box opens, as shown in Figure 5-6:
Figure 5-6:
Page Setup Dialog Box
Click the Printer button on the Page Setup dialog box. A new Page Setup dialog box appears, which displays the
Figure 5-7:
Displaying the Printer Status
Click the Network button to displays all the printers available on the network, as shown in Figure 5-8:
Figure 5-8:
Connect to Printer Dialog Box
Click the OK button on the Page Setup dialog box. A Print dialog box opens, as shown in Figure 5-9:
Figure 5-9:
Print Dialog Box
Click OK to print the current file.
Click the Print Image tab. The image view of the Printer Management application appears, as shown in Figure 5-10:
Figure 5-10:
Printer Management Application with Print Image Tabbed Pane
Select File->Open to open an image in the Print Image tabbed pane, as shown in Figure 5-11:
Figure 5-11:
Displaying an Image File in the Print Image Tabbed Pane
Select File->Print->Print Default to print the current page. Select File->Print->Print Custom to print a customized book, as shown in Figure 5-4. When the end user selects the page format using the Page Format check box and specifies the number of pages in Number of Pages test box of the Book Interface dialog box. Now, clicks the Add in the Book button in the Book Interface dialog box. The results are displayed in the list box of the Book Interface, as shown in Figure 5-12:
Figure 5-12:
Displaying a Book Interface dialog
Click the Print button to print the book items.
The New Input/Output (NIO) API provides the java.nio and java.nio.channels packages for buffer management, advance I/O file system, and file locking mechanism. The java.nio package contains the ByteBuffer classes that allow you to store the contents of a text file. To read, write, and lock the text files, you can use the FileLock and FileChannel classes available in the java.nio.channels package.
This chapter explains how to develop a Text Editor application using the java.nio and java.nio.channels packages and create, edit, print, and save text files.
The Text Editor application allows you to read, write, print,
and lock a specific text file. You can also change the
The Text Editor application uses the following files:
Editor.java
: Creates a
ActionPerform.java
: Implements the commands to
create,
FontClass.java
: Creates a font dialog box that
provides options to change the type,
ColorClass.java : Creates a color dialog box with sliders. You can use this dialog box to specify the Red Green Blue (RGB) value and change the color of the file text.
PrintClass : Opens a print dialog box that allows you to print a document. You can also use this dialog box to change the properties of the document, such as page layout and paper quality.
Help.java : Creates a help dialog box that lists the steps to use the Text Editor.
Figure 6-1 shows the architecture of the Text Editor application:
Figure 6-1:
Architecture of the Text Editor
Application
The Editor.java file calls ActionPerform.java to perform the file edit, format, and lock operations. After the ActionPerform.java file implements these operations, it returns the results to the Editor.java file. The Editor.java file then displays the results to the end user. The ActionPerform.java file calls the PrintClass.java file to print a file. To change the font type, size, and style of the text file, the ActionPerform.java file calls the FontClass.java file. The ActionPerform.java file calls the ColorClass.java file to change the color of the file text.
If an end user selects the help file option, the Editor.java
file calls the ActionPerform.java file, which, in