• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

showing applet embedded in jsp

 
Greenhorn
Posts: 11
Hibernate jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am creating pie chart using jfreechart , I am dynamicaly taking the values from DB and showing them in pie form. I have two java file one for database and other is for showing applet (applet class have main , which calls the DB class). All code properly works well in java. But I want these to be run through jsp. such that it get embedded in jsp. I am trying many ways but unable to do it . Could you please guide me how to move forward.

Thanks
Abhishek

Below is my applet .java file
-------------------------------------------------
package Pie_Chart;

import javax.swing.*;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RefineryUtilities;

public class PieChart extends ApplicationFrame
{

private Object chart;


/**
* Creates a new demo instance.
*
* @param title the frame title.
*/
public PieChart(String title) {


super(title);

DB db = new DB();
db.dbConnect("jdbc:sqlserver://newinfomine:3468;instanceName=MSSQL2005", "eGActiveDB_762", "eGActiveDB_762" );
JPanel panel = new JPanel(new GridLayout(2, 2));
DefaultPieDataset dataset = new DefaultPieDataset();
DefaultPieDataset dataset1 = new DefaultPieDataset();
dataset.setValue("January "+DB.ravi_case, DB.ravi_case);
dataset.setValue("February "+DB.ravi_case_feb, DB.ravi_case_feb);
dataset.setValue("March "+DB.ravi_case_mar, DB.ravi_case_mar);

dataset1.setValue("January "+DB.pradeep_case, DB.pradeep_case);
dataset1.setValue("February "+DB.pradeep_case_feb, DB.pradeep_case_feb);
dataset1.setValue("March "+DB.pradeep_case_mar, DB.pradeep_case_mar);




JFreeChart chart1 = ChartFactory.createPieChart("Ravi Case", dataset, false, false, false);
JFreeChart chart2 = ChartFactory.createPieChart("Pradeep Case", dataset1, false, false, false);

panel.add(new ChartPanel(chart1));
panel.add(new ChartPanel(chart2));
panel.setPreferredSize(new Dimension(800, 600));
setContentPane(panel);



}

public static void main(String[] args)
{
PieChart demo = new PieChart("Pie Chart");
demo.setVisible(true);
}

}
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you been trying to do? What problem did you encounter?
Did you use <applet> tag to embed the applet into the JSP page?

 
abhishek rawat
Greenhorn
Posts: 11
Hibernate jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I even tried the <applet> tag but it is not loading in the browser, I searched Internet and used all the way but no success:(. Could you please help me, if possible a sample JSP calling this applet will be much appreciated.
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did you put in the applet tag? Were there any messages in the Java Console?

The code you posted is not an applet, so you would have had to rewrite it.
 
abhishek rawat
Greenhorn
Posts: 11
Hibernate jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"The code you posted is not an applet, so you would have had to rewrite it."

Sorry but could you please explain me why this is not applet. I am using third party API(jfreechart) to show bar and pie in applet.

 
abhishek rawat
Greenhorn
Posts: 11
Hibernate jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Tim... I got what you were trying to say .. it should extend Applet to be a applet.
 
abhishek rawat
Greenhorn
Posts: 11
Hibernate jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you guys have any idea ..How I will call the above file in jsp?
 
abhishek rawat
Greenhorn
Posts: 11
Hibernate jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you guys have any idea ..How I will call the above file in jsp?..which extends application frame...
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How I will call the above file in jsp?


By using an applet tag, as has been suggested before. Start reading here: http://download.oracle.com/javase/tutorial/deployment/applet/index.html

How I will call the above file in jsp?..which extends application frame...


As I said, you need to rewrite your code so that it extends Applet or JApplet.
 
Ranch Hand
Posts: 77
5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There should be no (J)Applet (or (J)Frame) used here. Instead:
  • Have a servlet access the DB*, prepare the image, and serve it as image content.
  • Use JSP to access the servlet and display the image that it produces.

  • * If Java client side code can access the DB, so can hackers. That is a bad thing. Hide the DB behind some protective servlet.
     
    abhishek rawat
    Greenhorn
    Posts: 11
    Hibernate jQuery Netbeans IDE
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi All,

    I tried to save my applet on the server machine using robot method and it is working properly



    But the issue here is..it is capturing whole screen ..instead of just applet...Please let me know if there is another way of saving applet .
     
    Andrew Thompson
    Ranch Hand
    Posts: 77
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    abhishek rawat wrote:..I tried to save my applet on the server machine using robot method and it is working properly ..
    But the issue here is..it is capturing whole screen



    What is the connection between showing a chart in a web page, and saving a screen-shot (of an applet or the screen) to the server?

    As to "it is working properly" - I bet you have not tried this yet in a situation where the server and client are 2 different machines. Would I win that bet? ;)
     
    Haina Minawa
    Ranch Hand
    Posts: 119
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    abhishek rawat wrote:But you guys have any idea ..How I will call the above file in jsp?..which extends application frame...



    As Andrew suggested before, you should consider the solution of generating an image version of the report in a Servlet, then push the image to client (via a call to the Servlet in your JSP page, maybe).
     
    reply
      Bookmark Topic Watch Topic
    • New Topic