代码出错,调试问题
从网上下载了如下代码:
package org.vivianj.jfreereport;
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Point2D;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.jfree.report.*;
import org.jfree.report.Boot;
import org.jfree.report.ElementAlignment;
import org.jfree.report.JFreeReport;
import org.jfree.report.ReportProcessingException;
import org.jfree.report.elementfactory.TextFieldElementFactory;
import org.jfree.report.modules.gui.base.PreviewDialog;
import org.jfree.ui.FloatDimension;
public class HelloWorld {
protected static class CloseHandler extends WindowAdapter{
public void windowClosing(final WindowEvent event)
{
System.exit(0);
}
}
public HelloWorld(){
// 获得创建报表需要用到的数据
final TableModel data = createData();
//获得报表要用到的报表定义内容
final JFreeReport report = createReportDefinition();
//将报表定义和数据结合
report.setData(data);
try
{
//将生成的报表放到预览窗口中
final PreviewDialog preview = new PreviewDialog(report);
preview.addWindowListener(new CloseHandler());
preview.pack();
//显示报表预览窗口
preview.setVisible(true);
}
catch (ReportProcessingException reep)
{
reep.printStackTrace();
}
}
/**
* 创建生成报表需要用到的数据
*
* @返回一个TableModel实例
*/
private TableModel createData(){
final Object[] columnNames = new String[]{ "Column1 ", "Column2 "};
final DefaultTableModel result = new DefaultTableModel(columnNames, 100);
int rownum = 0;
int colnum = 0;
for (;rownum < 100 ; rownum++)
{
result.setValueAt( "say Hello " + rownum + "次 ", rownum, 0);
result.setValueAt( "say World " + rownum + "次 " , rownum, 1);
}
return result;
}
/**
* 创建一个报表定义
*
* @返回一个报表定义实例
*/
private JFreeReport createReportDefinition()
{
final JFreeReport report = new JFreeReport();
report.setName( "A Very Simple Report ");
/**
* 定义要显示报表第一列的样式
*/
TextFieldElementFactory factory = new TextFieldElementFactory();
factory.setName( "T1 ");
factory.setAbsolutePosition(new Point2D.Float(0, 0));
// factory.setMinimumSize(new FloatDimension(150, 20));
factory.setColor(Color.black);
factory.setHorizontalAlignment(ElementAlignment.LEFT);
factory.setVerticalAlignment(ElementAlignment.MIDDLE);
factory.setNullString( "- ");
factory.setFieldname( "Column1 ");
report.getItemBand().addElement(factory.createElement());
/**
* 定义要显示报表第二列的样式
*/
factory = new TextFieldElementFactory();
factory.setName( "T2 ");
factory.setAbsolutePosition(new Point2D.Float(200, 0));
// factory.setMinimumSize(new FloatDimension(150, 20));
factory.setColor(Color.black);
factory.setHorizontalAlignment(ElementAlignment.LEFT);
factory.setVerticalAlignment(ElementAlignment.MIDDLE);
factory.setNullString( "- ");
factory.setFieldname( "Column2 ");
report.getItemBand().addElement(factory.createElement());
/**
* 返回一个报表定义的实例
*/
return report;
}
public static void main(final String[] args)
{
// 初始化JFreeReport
Boot.start();
//调用演示实例
new HelloWorld();
}
}
提示:The type org.jfree.util.StackableException cannot be resolved. It is indirectly
referenced from required .class files;
The import org.jfree.report.Boot cannot be resolved;
The import org.jfree.ui cannot be resolved;
Type mismatch: cannot convert from ReportProcessingException to Throwable(异常处理那里)
Boot.start();(Boot cannot be resolved)
问题出在哪里呀?
希望各位大侠帮帮忙!!!
急需解决!!!
[解决办法]
一些必要的jar包没导进来。