Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

jFreeChart in Applet using Eclipse IDE with VE

Thread view: 
scifluent@gmail.com - 18 Mar 2007 23:32 GMT
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);

    }
}
Arne Vajhøj - 19 Mar 2007 01:08 GMT
> 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
[quoted text clipped - 3 lines]
> 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
scifluent@gmail.com - 19 Mar 2007 01:24 GMT
> sciflu...@gmail.com wrote:
> > For some reason the code below will run fine in the sun applet viewer
[quoted text clipped - 13 lines]
>
> 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?
Arne Vajhøj - 19 Mar 2007 01:46 GMT
>> Does your ChartJar.jar have a Class-Path directive that points
>> to a location where the applet JVM can load the JFreeChart jar file ?
[quoted text clipped - 4 lines]
>
> 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
scifluent@gmail.com - 19 Mar 2007 02:52 GMT
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

> sciflu...@gmail.com wrote:
> >> Does your ChartJar.jar have a Class-Path directive that points
[quoted text clipped - 24 lines]
>
> Arne
Arne Vajhøj - 19 Mar 2007 03:14 GMT
> Wow. Thanks for the great suggstions!!!  I am still stuck here.
>
[quoted text clipped - 19 lines]
> 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
scifluent@gmail.com - 19 Mar 2007 04:08 GMT
I am running it currently from a folder on my Mac...so there shouldn't
be file protection issues..

> sciflu...@gmail.com wrote:
> > Wow. Thanks for the great suggstions!!!  I am still stuck here.
[quoted text clipped - 31 lines]
>
> Arne
Andrew Thompson - 19 Mar 2007 03:14 GMT
On Mar 19, 9:32 am, sciflu...@gmail.com 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.
Arne Vajhøj - 19 Mar 2007 03:15 GMT
> On Mar 19, 9:32 am, sciflu...@gmail.com wrote:
> ...
[quoted text clipped - 15 lines]
> 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
scifluent@gmail.com - 19 Mar 2007 04:05 GMT
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!

> > On Mar 19, 9:32 am, sciflu...@gmail.com wrote:
> > ...
[quoted text clipped - 19 lines]
>
> Arne
scifluent@gmail.com - 19 Mar 2007 04:23 GMT
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?

> > On Mar 19, 9:32 am, sciflu...@gmail.com wrote:
> > ...
[quoted text clipped - 19 lines]
>
> Arne
scifluent@gmail.com - 19 Mar 2007 06:47 GMT
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>

On Mar 18, 8:23 pm, sciflu...@gmail.com wrote:
> Yes Arne...  the webpage below is using JFreechart in an applet..
>
[quoted text clipped - 35 lines]
>
> > Arne
scifluent@gmail.com - 19 Mar 2007 17:09 GMT
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!!!

> On Mar 19, 9:32 am, sciflu...@gmail.com wrote:
> ...
[quoted text clipped - 22 lines]
>
> Andrew T.
Andrew Thompson - 19 Mar 2007 17:16 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.