import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.lang.*;
import javax.swing.JApplet;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
//import org.jfree.chart.demo.Time;


/**
 * A simple demonstration application showing how to create a line chart using data from a
 * {@link CategoryDataset}.
 */
public class LineChartDemo1 extends JApplet{

   private Connection con = null;

     @Override
    public void init(){


       // Connection con = null;

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();


    }catch(ClassNotFoundException e)
    {

    System.out.println(e);
    }catch(InstantiationException e)
{
System.out.println(e);
         }catch(IllegalAccessException e)
{
System.out.println(e);
         }

   final CategoryDataset dataset = createDataset()  ;
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(500, 270));
        //setContentPane(chartPanel);

        chartPanel.setPopupMenu(null);
        //add the chartPanel to the container (getContentPane is inherited from JApplet which AppletGraph extends).
        Container content = getContentPane();
        content.add(chartPanel);

             //JFreeChart jFreeChart = generateGraph();

        //Put the jFreeChart in a chartPanel
        //ChartPanel chartPanel = new ChartPanel(jFreeChart);
        //chartPanel.setPreferredSize(new Dimension(900,600));






     }//end of init method


//  public LineChartDemo1() {
//        //super("Line Chart");
//        final CategoryDataset dataset = createDataset()  ;
//        final JFreeChart chart = createChart(dataset);
//        final ChartPanel chartPanel = new ChartPanel(chart);
//        chartPanel.setPreferredSize(new Dimension(500, 270));
//        setContentPane(chartPanel);
//    }




    private CategoryDataset createDataset() {

        // row keys...
        final String series1 = "First";
        final String series2 = "Second";
        final String series3 = "Third";

        // column keys...
        final String type1 = "1";
        final String type2 = "2";
        final String type3 = "3";
        final String type4 = "4";
        final String type5 = "5";
        final String type6 = "6";
        final String type7 = "7";
        final String type8 = "8";
        final String type9 = "9";

        // create the dataset...
        final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        //Connection con = null;
        try {
     // Class.forName("com.mysql.jdbc.Driver").newInstance();

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/XCORE","root","helloworld");
      Statement stmt = con.createStatement();
      ResultSet rslt = stmt.executeQuery("SELECT SUM(ACTIVE) FROM STATISTICS WHERE");

      //Time time = new Time();
      System.currentTimeMillis();

     // Date date= new Date();


       //date =  time.getLocalDateTime((System.currentTimeMillis())*1000);
           //date.setMinutes(5);



      while(rslt.next()){
         for(int i = 0;i < 10; i++)
         {
        dataset.addValue(rslt.getInt(1), series1, String.valueOf(i));

         }
          }

      rslt.close();
                if(!con.isClosed())
        System.out.println("Successfully connected to " + "MySQL server using TCP/IP...");

    } catch(Exception e) {
      System.err.println("Exception: " + e.getMessage());
    } finally {
      try {
        if(con != null)
          con.close();
      } catch(SQLException e) {}
    }


    return dataset;

    }

    private JFreeChart createChart(final CategoryDataset dataset) {

        // create the chart...
        final JFreeChart chart = ChartFactory.createLineChart(
            "Xipx Statistics Graph",       // chart title
            "Time ",                    // domain axis label
            "Calls ",                   // range axis label
            dataset,                   // data
            PlotOrientation.VERTICAL,  // orientation
            true,                      // include legend
            true,                      // tooltips
            false                      // urls
        );


        chart.setBackgroundPaint(Color.white);

        final CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setRangeGridlinePaint(Color.white);

        // customise the range axis...
        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setAutoRangeIncludesZero(true);



        // customise the renderer...
        final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
//        renderer.setDrawShapes(true);

        renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,1.0f, new float[] {10.0f, 6.0f}, 0.0f));
        renderer.setSeriesStroke(
            1, new BasicStroke(
                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {6.0f, 6.0f}, 0.0f
            )
        );
        renderer.setSeriesStroke(
            2, new BasicStroke(
                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {2.0f, 6.0f}, 0.0f
            )
        );
        // OPTIONAL CUSTOMISATION COMPLETED.

        return chart;
    }


}

_________________________________________________
Classpath has been set ... but the applet is still not working

Recommended Answers

All 2 Replies

Welcome nabeelanwer.

Read this http://www.daniweb.com/forums/announcement9-3.html.

Your java code must be surrounded with bb code tags.

You cannot perform sql operation with an applet. If you want to do so then you have to work with java policy & security manager system.

I never attempted this, neither I had opportunity and interest to work with applets but according to Sun tutorials it is possible to do it. Just have look at this example that is "nicked" fro Sun

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.