The code to generate the above GUI is quite simple and won't
surprise anyone used to Swing programming. We just instantiate a
ViewerPanel and add it to a JFrame. If you need to run this sample you
will find that it is part of the distribution.
package com.crionics.jpdf.samples.viewer;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import javax.swing.JFrame;
import com.crionics.jpdf.PdfException;
import com.crionics.jpdf.viewer.ViewerPanel;
/**
* Sample demo which bundles the ViewerPanel in a Frame.
*/
public class SampleViewerFrame extends JFrame
{
private ViewerPanel viewer;
public SampleViewerFrame() throws IOException, PdfException
{
setTitle("jPDF Viewer Sample");
// End the application when the window closes:
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) { System.exit(0);}
});
// Create the pdf viewer panel:
viewer = new ViewerPanel();
setContentPane(viewer);
// Uncomment this line to preload a document:
//viewer.loadDocument(new File("mydocument.pdf"));
pack();
}
public static void main(String arg[]) throws Exception
{
SampleViewerFrame f = new SampleViewerFrame();
f.setVisible(true);
}
}