Magazine
 
Tips & Tricks
 



FileFilterClass

This class is responsible to filter files. When file chooser opens a dialog box to open or save the file, file filter gives an option to choose only filtered files. In this example, FileFilterClass class has been created to filter java files.

import java.io.*;
import javax.swing.filechooser.FileFilter;
//Class responsible to filter java files.
public class FileFilterClass extends FileFilter {
public boolean accept (File file) {
return file.getName ().toLowerCase
().endsWith (“.java”)|| file.isDirectory ();
}
public String getDescription () {
return “Only Java Files (*.java)”;
}
}

The result of creating this class can be seen in
the figure below. When you click open menu,
an open dialog is opened like below:

 


Now you can check rest of the functionalities like copy, cut, paste, save and quit work properly and also add more new functions to make it more modern.

2- Create PDF file with Java Program

Sometimes, you may need creating a PDF (Portable Document Format). iText is a java library that contains classes to generate documents in PDF, XML, HTML, and RTF. For this you need to place iText.jar file to lib folder
of your JDK and set classpath for it. You can download this jar file from the link http:// www.lowagie.com/iText/download.html The program below will create PDF for you. Just have a glance over the program below:

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
public class JavaPDF{
public static void main(String arg[])throws
Exception{
//Create a document-object
Document document=new Document();
String p2 = “JavaJazzUp is a new wing of
Roseindia.net that is initiated to provide the
full-fledged and in-depth information to a wide
range of Java lovers. A magazine has a
characteristics of having a vast segments
related to a wide range of public choice and
must contain at least a portion of every
categories choice. So RoseIndia.net has decided

Oct 2007 | Java Jazz Up | 71
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70, 71, 72, 73, 74, 75, 76, 77, 78,   Download PDF