Without seeing a lot more of your code, I couldn't say for absolute certain (i.e. what's in your paint/repaint method?)
I threw your code into eclipse and added some of my applet code, and it appears to work... Take a look at this:
Code: Select all
package jannisery;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JApplet;
import org.jfree.chart.*;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.chart.plot.PlotOrientation;
public class jannisery_problem_applet extends JApplet {
static final long serialVersionUID=1;
public DefaultCategoryDataset dataset = new DefaultCategoryDataset();
public ChartPanel chartPanel;
public JFreeChart chart;
//BELOW IS THE METHOD WE'RE GIVEN TO WORK WITH FROM THE FORUM
public void DrawChart() {
initDataSet();
// create the chart...
chart = ChartFactory.createBarChart(
"Bar Chart", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
chartPanel = new ChartPanel(chart);
//I ADDED THIS FOR TESTING...
setContentPane(chartPanel);
//I DON'T CARE ABOUT THE PREFERRED SIZE FOR NOW...
//chartPanel.setPreferredSize(new Dimension(panel1.getHeight(),panel1.getWidth()));
//I DON'T KNOW WHAT PANEL1 IS EXACTLY...
//panel1.add(chartPanel);
//THIS APPEARS TO BE PART OF THE GUI ... I DON'T CARE ABOUT IT RIGHT NOW...
//JOptionPane.showMessageDialog( null, ""+panel1.getComponentCount());
//AGAIN ... SINCE WE DON'T HAVE A PANEL1, WE'RE NOT GOING TO USE THIS
//panel1.validate();
//panel1.repaint();
}
//EVERYTHING BELOW HERE I ADDED TO MAKE THIS WORK.
public void initDataSet() {
//INITIALIZE PUBLICLY ACCESSIBLE DATA SET HERE
return;
}
public void paint(Graphics g) {
//IF WE HAVE A CHART TO DISPLAY...
if ( chart!=null ) {
chart.draw( (Graphics2D)g,getBounds());
}
}
public void init() {
DrawChart();
}
}
Specifically, I added a paint method and an init method that just calls your DrawChart method. Again, without seeing the rest of the code, I couldn't nail down exactly what's wrong with it.[/code]