程序界面图:
代码清单:
package 将图片组合成PDF文件;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfWriter;
/*
* 绘制主界面以及处理按钮事件类——Jiemian_main
*
* */
class Jiemian_mian extends JFrame{
private static final long serialVersionUID = 1657254256189721759L;
final private String shuoming = " 使用说明: 本程序的主要功能就是将图片组按比例缩放合成于同一PDF文件里。 ——winmin";
private String dir_open = "";
private String dir_save = "";
public JFrame jf = null;
private JPanel jp = null;
private JButton jb_open = null;
private JButton jb_save =null;
private JButton jb_ok = null;
private JTextField jt_dir_open = null;
private JTextField jt_dir_save = null;
private JLabel jl_dir_open = null;
private JLabel jl_dir_save = null;
private JLabel jl_lujing_open = null;
private JLabel jl_lujing_save = null;
private JTextField jtf = null;
public Jiemian_mian(){
jf = new JFrame("将图片组合成PDF文件");
jp = new JPanel();
jp.setLayout(null);
/*标签*/
jl_dir_open = new JLabel("请选择图片组所在的文件夹:");
jl_dir_save = new JLabel("请选择PDF的合成位置:");
jl_lujing_open = new JLabel("路径:");
jl_lujing_save = new JLabel("路径:");
jl_dir_open.setBounds(50, 50, 200, 20);
jl_dir_save.setBounds(420, 50, 200, 20);
jl_lujing_open.setBounds(50, 80, 40, 20);
jl_lujing_save.setBounds(420, 80, 40, 20);
jp.add(jl_dir_open);
jp.add(jl_dir_save);
jp.add(jl_lujing_open);
jp.add(jl_lujing_save);