jFreeChart in Applet using Eclipse IDE with VE

S

scifluent

Hi!

For some reason the code below will run fine in the sun applet viewer
but will not deploy in my Safari or Firefox browser. All I get is the
java loading indicator and then a red "x" in the window it should be
working in. I exported the class into an uncompressed .jar file to
eliminate the issue mentioned at:
http://www.velocityreviews.com/forums/t132903-problem-deploying-applet.html
but no improvement.

Anyone made this hurdle?

Web page:

<html>
<body>

<applet code= ChartApplet.class
archive="ChartJar.jar"
width=500 height=500>
</applet>

</body>
</html>



Code made using Eclipse with the assistance of VE:



import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.TitledBorder;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class ChartApplet extends JApplet {

/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private ChartPanel chartPanel;

private String columnNames[];
private String dataValues[][];

protected XYSeriesCollection chartDataSet = new XYSeriesCollection();
protected ArrayList <String> chartPlotType = new
ArrayList<String>(); // @jve:decl-index=0:
protected String chartTitle = "Hey";
protected String chartYAxisTitle = "Wow";
protected String chartXAxisTitle = "NoWay";

/**
* This is the xxx default constructor
*/
public ChartApplet() {
super();
}

/**
* This method initializes this
*
* @return void
*/
public void init() {
dummyChart();
this.setContentPane(getJContentPane());

}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
FlowLayout flowLayout = new FlowLayout();
flowLayout.setHgap(9);
flowLayout.setVgap(27);
jContentPane = new JPanel();
jContentPane.setLayout(flowLayout);
jContentPane.add(chartPanel);
}
return jContentPane;
}

// jFreeChart

public void createChart(){
JFreeChart chart = createChart(chartDataSet);
chartPanel = new ChartPanel(chart);
chartPanel.setBorder(BorderFactory.createTitledBorder(new
SoftBevelBorder(SoftBevelBorder.RAISED), "Option Chart",
TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION, null, null));
}

protected JFreeChart createChart(XYDataset dataset) {

JFreeChart chart = ChartFactory.createXYAreaChart(
chartTitle,
chartXAxisTitle, chartYAxisTitle,
dataset,
PlotOrientation.VERTICAL,
true, // legend
true, // tool tips
false // URLs
);

chart.setBackgroundPaint(Color.white);

XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setForegroundAlpha(0.65f);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);

ValueAxis domainAxis = plot.getDomainAxis();
domainAxis.setTickMarkPaint(Color.black);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);

ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setTickMarkPaint(Color.black);

return chart;
}

private void dummyChart(){

for (int j = 0; j < 2; j++){

ArrayList<Float> xdata = new ArrayList<Float>();
ArrayList<Float> ydata = new ArrayList<Float>();

for (int i = 0; i < 10; i++) {
xdata.add((float)i);
ydata.add((float) i * .10f);
}

xdata.trimToSize();
ydata.trimToSize();

this.addChartSeriesXandYValues("Test", xdata, ydata,"Shape");
this.createChart();
}
}

public void addChartSeriesXandYValues(String series_title_in,
ArrayList<Float> x_data_in,
ArrayList<Float> y_data_in, String plot_type) {

XYSeries newSeries = new XYSeries(series_title_in);

ArrayList<Float> seriesX = x_data_in;
ArrayList<Float> seriesY = y_data_in;

for(int i = 0; i < seriesX.size(); i++)
newSeries.add(seriesX.get(i), seriesY.get(i));

chartDataSet.addSeries(newSeries);
chartDataSet.setIntervalWidth(0.0);
chartPlotType.add(plot_type);

}
}
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

For some reason the code below will run fine in the sun applet viewer
but will not deploy in my Safari or Firefox browser. All I get is the
java loading indicator and then a red "x" in the window it should be
working in. I exported the class into an uncompressed .jar file to
eliminate the issue mentioned at:
http://www.velocityreviews.com/forums/t132903-problem-deploying-applet.html
but no improvement.
<applet code= ChartApplet.class
archive="ChartJar.jar"
width=500 height=500>
</applet>

Does your ChartJar.jar have a Class-Path directive that points
to a location where the applet JVM can load the JFreeChart jar file ?

Arne
 
S

scifluent

Does your ChartJar.jar have a Class-Path directive that points
to a location where the applet JVM can load the JFreeChart jar file ?

Arne

Hello Arne!

I guess I thought all of the necessary JFreechart methods were
imported through import statements into the class file when it was
compiled. The only file I have in the ChartJar.jar is
"ChartApplet.class" ..

I guess I should ask... what do I need to include in my deployment jar?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

I guess I thought all of the necessary JFreechart methods were
imported through import statements into the class file when it was
compiled. The only file I have in the ChartJar.jar is
"ChartApplet.class" ..

I guess I should ask... what do I need to include in my deployment jar?

No no.

import org.jfree.chart.ChartFactory;

mean that you can refer to the class by the short name
ChartFactory instead of the full name org.jfree.chart.ChartFactory - it
does not include anything in the class file.

Put a manifest in your ChartJar.jar with one line:

Class-Path: jfreechart.jar jcommon.jar

(correct the names to the actual)

And place those two jar files at the web server in the
same dir as your jar file.

Arne
 
S

scifluent

Wow. Thanks for the great suggstions!!! I am still stuck here.

jar tf ChartJar.jar results in:

META-INF/MANIFEST.MF
applet/ChartApplet.class

My manifest file doesn't work with either:

Manifest-Version: 1.0
Class-Path: jfreechart-1.0.0-rc1.jar jcommon-1.0.0-rc1.jar

or

Manifest-Version: 1.0
Class-Path: ../jfreechart-1.0.0-rc1.jar ../jcommon-1.0.0-rc1.jar


My directory that I run the html in contains:

ls results in:

ChartApplet.html jcommon-1.0.0-rc1.jar
ChartJar.jar jfreechart-1.0.0-rc1.jar

I am such a NOOB with this being that I have run everything for the
last 5 months in an IDE using command line control.


My guess is that I am just one step away...but don't know what that
is? Help?

TIA!!!

Penn
 
A

Andrew Thompson

On Mar 19, 9:32 am, (e-mail address removed) wrote:
....
<html>
<body>

<applet code= ChartApplet.class
archive="ChartJar.jar"

archive="ChartJar.jar, JFreeChart.jar"
width=500 height=500>
</applet>

</body>
</html>

Note that adding the JFreeChart.jar* to a manifest
is more applicable to (non JWS) desktop applications.
I have never heard of it being done with applets.

* I just made up that name, change it as appropriate.

HTH

Andrew T.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Wow. Thanks for the great suggstions!!! I am still stuck here.

jar tf ChartJar.jar results in:

META-INF/MANIFEST.MF
applet/ChartApplet.class

My manifest file doesn't work with either:

Manifest-Version: 1.0
Class-Path: jfreechart-1.0.0-rc1.jar jcommon-1.0.0-rc1.jar

or

Manifest-Version: 1.0
Class-Path: ../jfreechart-1.0.0-rc1.jar ../jcommon-1.0.0-rc1.jar

My directory that I run the html in contains:

ls results in:

ChartApplet.html jcommon-1.0.0-rc1.jar
ChartJar.jar jfreechart-1.0.0-rc1.jar

Class-Path: jfreechart-1.0.0-rc1.jar jcommon-1.0.0-rc1.jar

sounds right.

Make sure that there are a new line after it.

Also be sure that file protection allows the web server to
serve the two extra jar files.

Arne
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Andrew said:
On Mar 19, 9:32 am, (e-mail address removed) wrote:
...

archive="ChartJar.jar, JFreeChart.jar"


Note that adding the JFreeChart.jar* to a manifest
is more applicable to (non JWS) desktop applications.
I have never heard of it being done with applets.

I have used it with applets. Including with JFreeChart.

Arne
 
S

scifluent

Yes there is a new line after the Class-Path in the manifest file.

When I create the jar file...is there anything I should make sure I
check? Like

"Add directory entries" (I've tried it both ways)

or something similar?

Do the freechart jars need to be uncompressed or something?

Thanks!
 
S

scifluent

I am running it currently from a folder on my Mac...so there shouldn't
be file protection issues..
 
S

scifluent

Yes Arne... the webpage below is using JFreechart in an applet..

http://www.object-refinery.com/jfreechart/applet.html

Viewing the html source, the Jfreechart jars appear to be in the
Archive call.

<APPLET ARCHIVE="jfreechart-0.9.4-premium-demo-
applets.jar,jfreechart-0.9.4.jar,jcommon-0.7.1.jar"
CODE="com.jrefinery.chart.premium.demo.applet.Applet1" width=640
height=260 ALT="You should see an applet, not this text.">
</APPLET>

I have tried this as well... but it didn't work. Is there something
to this though?
 
S

scifluent

Nailed it.... Using the html that I found and placed in the previous
post as a guide.

With the ChartApplet.class in a jar and it's code path specifically
laid out.

Thanks Arne for the guidance!!!

<html>
<body>

<applet code= "applet/ChartApplet.class"
archive="ChartJar.jar, jfreechart-1.0.0-rc1.jar, jcommon-1.0.0-
rc1.jar"
width="500" height="500">
</applet>



</body>
</html>
 
S

scifluent

Thanks for you input Andrew...but Arne is right. I don't actually
need the archive calls in the applet line, a manifest file does it
all. Final answer is I can use

<applet code= "applet/ChartApplet.class"
archive="ChartJar.jar"
width="500" height="500">
</applet>

with the appropriate Class Paths in the ChartJar.jar leading to the
JFreechart jars.

Thanks!!!
 
A

Andrew Thompson

Thanks for you input Andrew...but Arne is right. I don't actually
need the archive calls in the applet line, a manifest file does it
all.

Thanks for confirming Arne's answer (I believed
him, but it also helps others who might find
this thread later). Glad you got it working.

As an aside, please put replies *below* text,
and trim earlier text no longer relevant, when
replying.

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top