Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 16 of 16

Thread: CALLING APPLET IN JSP

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post CALLING APPLET IN JSP

    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
    -------------------------------------------------
    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);
    }
     
    }
    Last edited by Freaky Chris; November 3rd, 2011 at 06:15 AM.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: CALLING APPLET IN JSP

    Hi Abhishek,

    please use [highlight=java][/highlight] when posting Java code snippets 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

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: CALLING APPLET IN JSP

    Quote Originally Posted by rawabhishek View Post
    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
    -------------------------------------------------
    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.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: CALLING APPLET IN JSP

    Quote Originally Posted by rawabhishek View Post
    Hi,
    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
    Last edited by macko; November 3rd, 2011 at 09:06 AM.

  6. #6
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default 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 there isnt a main method in an applet... it runs via the class file method name first..

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: CALLING APPLET IN JSP

    Quote Originally Posted by macko View Post
    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 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)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default 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()

    and ye constructor..

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: CALLING APPLET IN JSP

    Please remember i'm lazy 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.

  11. #11
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: CALLING APPLET IN JSP

    Anyways, getting back to your original question now, you can call you applet by,
    <jsp:plugin type="applet" code="PATHOFYOURAPPLET" codebase="PATHWHEREAPPLETRESIDES">

  12. #12
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  13. #13
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: CALLING APPLET IN JSP

    Sure anytime. Good luck and you must read about applets first before trying anything...

  14. #14
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.
    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);
    }

  15. #15
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: CALLING APPLET IN JSP

    Quote Originally Posted by rawabhishek View Post
    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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  16. #16
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: CALLING APPLET IN JSP

    Quote Originally Posted by rawabhishek View Post
    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.
    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

Similar Threads

  1. Replies: 0
    Last Post: October 13th, 2011, 07:42 PM
  2. about calling sub class
    By pokuri in forum Object Oriented Programming
    Replies: 3
    Last Post: January 11th, 2011, 03:30 PM
  3. calling SingleFrameApplication
    By petem86 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 8th, 2010, 09:06 AM
  4. calling a constructor
    By turnwellm in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 3rd, 2010, 08:46 PM
  5. Calling for methods
    By soccer_kid_6 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 1st, 2010, 12:13 AM