import java.applet.Applet;
import java.awt.Button;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class test1_librery extends Applet implements ActionListener{
/**
 * 
 */
private static final long serialVersionUID = 216075068429090984L;
TextField t1=new TextField();
TextField t2=new TextField();
Button b1=new Button("下一个");
Button b2=new Button("生成");
Label l1=new Label("请输入书号:");
Label l2=new Label("请输入册数:");
String s1[]=new String[50]; int s2[]=new int[50];
int i=0;
public void init()
{   t1.setSize(200, 300);
        
    add(l1);   
add(t1);
add(l2);
add(t2);
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
} public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="下一个");
{System.out.println(t1.getText());

s1[i]=t1.getText();
s2[i++]=t2.getText().charAt(0)-48;
t1.setText(null);
t2.setText(null);

}
if(e.getActionCommand()=="生成")
{  


 Document doc=new Document();         try {         //定义输出位置并把文档对象装入输出对象中            PdfWriter.getInstance(doc, new FileOutputStream("c:/xhy.pdf"));             //打开文档对象             doc.open();          // 加入文字“Hello World”
            while (i>=0) {
System.out.println(s1[i]+"   :"+s2[i]);

                    while(s2[i]-->0)
            doc.add(new Paragraph(s1[i]));
                 
                    i--;
            }          //  关闭文档对象,释放资源             doc.close();                    } catch (FileNotFoundException a) {            a.printStackTrace();         } catch (DocumentException a) {            a.printStackTrace();              } }
}
}
结果是每输入一个都要换行 那么我该用什么方法控制他的输入格式

解决方案 »

  1.   

    LZ可以用表格或坐标方式输出try {
        table = new Table(2,3);
        Cell titleZh = new Cell(new Paragraph("中文示例",getChineseFont()));
        Cell cellZh = new Cell(new Paragraph(getZhcontext(),getChineseFont()));
        Cell titleEn = new Cell(new Paragraph("英文示例",getChineseFont()));
        Cell cellEn = new Cell(getEncontext());
        System.out.println(titleZh.getMaxLines());
        System.out.println(cellZh.getChunks());//     Cell titleZh = new Cell("1");
    //     Cell cellZh = new Cell("2");
    //     Cell titleEn = new Cell("3");
    //     Cell cellEn = new Cell("4");
        
        table.addCell(titleZh);
        table.addCell(cellZh);
        table.addCell(titleEn);
        table.addCell(cellEn);
        
    } catch (BadElementException e) {
        e.printStackTrace();
    }
    try {
        doc.add(table);
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
      

  2.   

    呵呵
    有好多第三方的组建就可以给你做了啊
    我用的是ireport,还不是很熟练,不过用起来还好啊!