if someone wonders about the code that i have written, i am pasting it here. sorry its a bit too much, however!
I am using a free library called Chart2D from sourceforge.net.
I have used it
http://chart2d.sourceforge.net/ and written the following. I get APPLET NOTINITED error when i load the applet, so i checked for the exception in Java console from control panel and it says java.lang.ClassCastException
++++++++++++
code
++++++++++++
import net.sourceforge.chart2d.*;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import java.awt.Color;
import java.util.Random;
import java.io.*;
/**
* A Chart2D demo demonstrating the LBChart2D object.
* Container Class: JFrame<br>
* Program Types: Applet or Application<br>
*/
public class LBChart2DFrameDemo extends JApplet {
//Data for reading from file
private JFrame frame = null;
private static boolean isApplet = true;
/**
* For running as an application.
* Calls init() and start().
* @param args An unused parameter.
*/
public static void main (String[] args) {
isApplet = false;
LBChart2DFrameDemo demo = new LBChart2DFrameDemo();
demo.init();
demo.start();
//exit on frame close event
}
/**
* Configure the chart and frame, and open the frame.
*/
public void init() {
//Start configuring a JFrame GUI with a JTabbedPane for
multiple chart panes
JTabbedPane panes = new JTabbedPane();
panes.addTab ("Line", getChart2DDemoF());
//for scaling dymanically
boolean dynamicSizeCalc = false;
if (dynamicSizeCalc) {
int maxWidth = 0;
int maxHeight = 0;
for (int i = 0; i < panes.getTabCount(); ++i) {
Chart2D chart2D = (Chart2D)panes.getComponentAt (i);
chart2D.pack();
Dimension size = chart2D.getSize();
maxWidth = maxWidth > size.width ? maxWidth :
size.width;
maxHeight = maxHeight > size.height ? maxHeight :
size.height;
}
Dimension maxSize = new Dimension (maxWidth, maxHeight);
System.out.println (maxSize);
for (int i = 0; i < panes.getTabCount(); ++i) {
Chart2D chart2D = (Chart2D)panes.getComponentAt (i);
chart2D.setSize (maxSize);
chart2D.setPreferredSize (maxSize);
}
System.out.println (panes.getPreferredSize());
}
else {
Dimension maxSize = new Dimension (561, 214);
for (int i = 0; i < panes.getTabCount(); ++i) {
Chart2D chart2D = (Chart2D)panes.getComponentAt (i);
chart2D.setSize (maxSize);
chart2D.setPreferredSize (maxSize);
}
panes.setPreferredSize (new Dimension (566 + 5, 280 +
5)); //+ 5 slop
}
frame = new JFrame();
frame.getContentPane().add (panes);
frame.setTitle ("NWR Vs Cycles Graph");
frame.addWindowListener (
new WindowAdapter() {
public void windowClosing (WindowEvent e) {
destroy();
} } );
frame.pack();
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation (
(screenSize.width - frame.getSize().width) / 2,
(screenSize.height - frame.getSize().height) / 2);
}
/**
* Shows the JFrame GUI.
*/
public void start() {
frame.show();
}
static int count=0;
public String[] readXAxisFile()
{
String[] xAxisValues= new String[1000];
String text;
try
{
FileReader inputFile = new
FileReader("E:/11th/nwr/output/xaxis.dat");;
BufferedReader fileInput = new BufferedReader(inputFile);
int k=0;
while((text =
fileInput.readLine()).compareTo(("###")) != 0)
{
xAxisValues[k++]=text;
count++;
}
inputFile.close();
return xAxisValues;
}
catch(IOException e)
{
System.out.println(e.getMessage());
return null;
}
}
public float[] readYAxisFile()
{
float[] yAxisValues= new float[1000];
String text;
try
{
FileReader inputFile = new
FileReader("E:/11th/nwr/output/nwr.dat");;
BufferedReader fileInput = new BufferedReader(inputFile);
int k=0;
while((text =
fileInput.readLine()).compareTo(("###")) != 0)
{
yAxisValues[k++]=Float.parseFloat(text);
}
inputFile.close();
return yAxisValues;
}
catch(IOException e)
{
System.out.println(e.getMessage());
return null;
}
}
/**
* Ends the application or applet.
*/
public void destroy() {
if (frame != null) frame.dispose();
if (!isApplet) System.exit (0);
}
/**
* Builds the demo chart.
* @return The demo chart.
*/
private Chart2D getChart2DDemoF() {
//<-- Begin Chart2D configuration -->
//Configure object properties
Object2DProperties object2DProps = new Object2DProperties();
object2DProps.setObjectTitleText ("NWR Vs Cycles");
//Configure chart properties
Chart2DProperties chart2DProps = new Chart2DProperties();
//Configure legend properties
LegendProperties legendProps = new LegendProperties();
String[] legendLabels = {"NWR"};
legendProps.setLegendLabelsTexts (legendLabels);
//Configure graph chart properties
GraphChart2DProperties graphChart2DProps = new
GraphChart2DProperties();
String[] xAxis = readXAxisFile();
graphChart2DProps.setLabelsAxisLabelsTexts (xAxis);
graphChart2DProps.setLabelsAxisTitleText ("Cycles");
graphChart2DProps.setNumbersAxisTitleText ("NWR");
graphChart2DProps.setChartDatasetCustomizeGreatestValue
(true);
graphChart2DProps.setChartDatasetCustomGreatestValue (1000);
graphChart2DProps.setLabelsAxisTicksAlignment
(graphChart2DProps.CENTERED);
//Configure graph properties
GraphProperties graphProps = new GraphProperties();
graphProps.setGraphBarsExistence (false);
graphProps.setGraphLinesExistence (true);
graphProps.setGraphOutlineComponentsExistence (true);
graphProps.setGraphAllowComponentAlignment (true);
//Configure dataset
// For y-axis values - NWR values
Dataset dataset = new Dataset (1, count, 1);
float[] yAxis = readYAxisFile();
for(int c=0;c<count;c++)
{
dataset.set (0, c, 0, yAxis[c]);
}
//Configure graph component colors
MultiColorsProperties multiColorsProps = new
MultiColorsProperties();
//Configure chart
LBChart2D chart2D = new LBChart2D();
chart2D.setObject2DProperties (object2DProps);
chart2D.setChart2DProperties (chart2DProps);
chart2D.setLegendProperties (legendProps);
chart2D.setGraphChart2DProperties (graphChart2DProps);
chart2D.addGraphProperties (graphProps);
chart2D.addDataset (dataset);
chart2D.addMultiColorsProperties (multiColorsProps);
//Optional validation: Prints debug messages if invalid
only.
if (!chart2D.validate (true)) chart2D.validate (false);
//<-- End Chart2D configuration -->
return chart2D;
}
********************
Pathma