Re: CALLING APPLET IN JSP
Hi Abhishek,
please use [highlight=java][/highlight] when posting Java code snippets :D i've done it for you this time. Just means we get to have formatting and syntax highlighting.
What problems arise when using a JApplet? Errors etc?
Regards,
Chris
Re: CALLING APPLET IN JSP
Quote:
Originally Posted by
rawabhishek
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. Could you please guide me how to move forward.
Thanks
Abhishek
Below is my applet .java file
-------------------------------------------------
Code java:
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;
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);
}
}
By creating the name applet.java will never make it applet. Well, getting back to your question, google it and you can get hundred of results for your query.
Re: CALLING APPLET IN JSP
I doubt this question has much to do with JSP, and more to do with deploying an applet. JSP simply generates html- the html is what needs to embed the applet. I don't see any html, or any problems, or any specific "this is what happens", so we can't really help you.
Edit- Now that I'm looking at your code, I don't even see an applet!
Re: CALLING APPLET IN JSP
Quote:
Originally Posted by
rawabhishek
Hi,
Code java:
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 JApplet
{
private Object chart;
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);
}
}
Theres getting you into the right direction :D
Re: CALLING APPLET IN JSP
Sorry and i quote "Why the hell did i post in the main method heh" I had just noticed its suppose to be an applet :P there isnt a main method in an applet... it runs via the class file method name first..
Re: CALLING APPLET IN JSP
Quote:
Originally Posted by
macko
Sorry and i quote "Why the hell did i post in the main method heh" I had just noticed its suppose to be an applet :P there isnt a main method in an applet... it runs via the class file method name first..
Bwah? An applet runs from the init() method, not the class file method name (you mean constructor?).
Lesson: Java Applets (The Java™ Tutorials > Deployment)
Re: CALLING APPLET IN JSP
I had developed a custom multi-threaded chat server/client for my advanced java class abit ago..
When i had converted it from JFrame to JApplet.. i had no init() included.. or start() run() stop() so on..
it seemed to work from the main file name class..
clientDisplay.java
public clientDisplay(){
}
It seemed to run perfectly from there besides the minor facts such as host exception & image difficulty..
but point being ye.. it should work even without an init() :P
and ye constructor..
Re: CALLING APPLET IN JSP
I see what you're saying. Yeah, the constructor is called first, where you should do any pre-loading and whatnot. Then its init() function is called, where you should actually start the processes. I guess for simple stuff it doesn't matter which one you use, but for more advanced stuff, you'll want to use that init function.
Re: CALLING APPLET IN JSP
Please remember i'm lazy :P and plus i was simply converting it via JFrame.. No point of adding all the side sections and moving code around ^^ but ye if you wanted special functions to be executed on load, on exit, on stop etc... then yep your 100% right.
Re: CALLING APPLET IN JSP
Anyways, getting back to your original question now, you can call you applet by,
Code :
<jsp:plugin type="applet" code="PATHOFYOURAPPLET" codebase="PATHWHEREAPPLETRESIDES">
Re: CALLING APPLET IN JSP
ohh,,,that was quite long discussion :)...Thanks guys I realy appriciate it ....
let me try the <applet> tag....... please keep checking thread .. I may nee your help...Thanks
Re: CALLING APPLET IN JSP
Sure anytime. Good luck and you must read about applets first before trying anything...:)
Re: CALLING APPLET IN JSP
Hi All,
I tried my best to call the applet but it was not loading on jsp.... So I thought why not save the applet as image and then call it into the JSP....I used the robot class..but it is capturing whole my desktop like printscreen and saving it into the server. ..Below is my code please let me know if there is another best way to do so.
Code java:
try{
BufferedImage screencapture = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );
// Save as JPEG
File file = new File("c:/report_image_format.jpg");
ImageIO.write(screencapture, "jpg", file);
}catch(Exception e)
{
LOG.info("Screen Capture Error : "+e);
}
Re: CALLING APPLET IN JSP
Quote:
Originally Posted by
rawabhishek
Hi All,
I tried my best to call the applet but it was not loading on jsp.... So I thought why not save the applet as image and then call it into the JSP....I used the robot class..but it is capturing whole my desktop like printscreen and saving it into the server. ..Below is my code please let me know if there is another best way to do so.
What? What do you expect to accomplish with that? Anyway, you're passing a Rectangle that is the whole screen into the createScreenCapture() method, so what did you expect to happen?
Like I said, you're going to need to post the HTML that your JSP is generating.
Re: CALLING APPLET IN JSP
Quote:
Originally Posted by
rawabhishek
Hi All,
I tried my best to call the applet but it was not loading on jsp.... So I thought why not save the applet as image and then call it into the JSP....I used the robot class..but it is capturing whole my desktop like printscreen and saving it into the server. ..Below is my code please let me know if there is another best way to do so.
Code java:
try{
BufferedImage screencapture = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );
// Save as JPEG
File file = new File("c:/report_image_format.jpg");
ImageIO.write(screencapture, "jpg", file);
}catch(Exception e)
{
LOG.info("Screen Capture Error : "+e);
}
You must try this