我正在尝试制作一个显示3D饼图的简单小程序,但是我得到了一个
RuntimeException (`java.lang.NoClassDefFoundError: org/jfree/chart/ChartPanel`)
我一直在试图找出原因,并认为这可能是applet能够读取我使用的第三方库的问题。它在NetBeans中运行良好,但在浏览器中我一直收到错误。我有什么不对的任何线索?代码如下:
HTML:
<APPLET codebase="classes" code="CyberThreatApplet/CyberThreatApplet.class"
archive="jfreechart-1.0.19.jar,jcommon-1.0.23.jar" width=350 height=200>
</APPLET>
爪哇:
package CyberThreatApplet;
import java.awt.Dimension;
import javax.swing.JApplet;
import org.jfree.chart.*;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.*;
import org.jfree.util.Rotation;
public class CyberThreatApplet extends JApplet
{
@Override
public void init()
{
CreateChart("Cyber Attack Pie Chart","Motivations Behind Cyber Attacks - May 2013");
}
private void CreateChart(String appTitle, String chartTitle)
{
PieDataset dataset = createDataset();
JFreeChart chart = createChart(dataset,chartTitle);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500,300));
add(chartPanel);
}
private PieDataset createDataset()
{
DefaultPieDataset result = new DefaultPieDataset();
result.setValue("Cybercrime",46);
result.setValue("Hacktivism",36);
result.setValue("Cyber Espionage",9);
result.setValue("Cyber Warfare",9);
return result;
}
private JFreeChart createChart(PieDataset dataset,String title)
{
JFreeChart chart = ChartFactory.createPieChart3D(title,dataset,true,true,false);
PiePlot3D plot = (PiePlot3D)chart.getPlot();
plot.setStartAngle(90);
plot.setDirection(Rotation.CLOCKWISE);
plot.setForegroundAlpha(0.75f);
return chart;
}
}
答案 0 :(得分:1)
确保jfreechart-1.0.19.jar
(和所有其他jar)位于相对于HTML文件的classes
目录中