Ask Experts Questions for FREE Help !
Ask
    Fazalshaik's Avatar
    Fazalshaik Posts: 1, Reputation: 1
    New Member
     
    #1

    Aug 16, 2015, 12:56 AM
    Java query please help me
    the below is a graph java code


    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;


    import javax.swing.Timer;
    import javax.swing.JPanel;


    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.XYPlot;
    import org.jfree.data.time.Millisecond;
    import org.jfree.data.time.TimeSeries;
    import org.jfree.data.time.TimeSeriesCollection;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;


    /**
    * An example to show how we can create a dynamic chart.
    */
    public class DynamicLineAndTimeSeriesChart extends ApplicationFrame implements ActionListener {


    /** The time series data. */
    private TimeSeries series;


    /** The most recent value added. */
    private double lastValue = 100.0;


    /** Timer to refresh graph after every 1/4th of a second */
    private Timer timer = new Timer(250, this);


    /**
    * Constructs a new dynamic chart application.
    *
    * @param title the frame title.
    */
    public DynamicLineAndTimeSeriesChart(final String title) {


    super(title);
    this.series = new TimeSeries("Random Data", Millisecond.class);


    final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
    final JFreeChart chart = createChart(dataset);


    timer.setInitialDelay(1000);


    //Sets background color of chart
    chart.setBackgroundPaint(Color.LIGHT_GRAY);


    //Created JPanel to show graph on screen
    final JPanel content = new JPanel(new BorderLayout());


    //Created Chartpanel for chart area
    final ChartPanel chartPanel = new ChartPanel(chart);


    //Added chartpanel to main panel
    content.add(chartPanel);


    //Sets the size of whole window (JPanel)
    chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));


    //Puts the whole content on a Frame
    setContentPane(content);


    timer.start();


    }


    /**
    * Creates a sample chart.
    *
    * @param dataset the dataset.
    *
    * @return A sample chart.
    */
    private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart(
    "Dynamic Line And TimeSeries Chart",
    "Time",
    "Value",
    dataset,
    true,
    true,
    false
    );


    final XYPlot plot = result.getXYPlot();


    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.lightGray);


    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setAutoRange(true);


    //Domain axis would show data of 60 seconds for a time
    xaxis.setFixedAutoRange(60000.0); // 60 seconds
    xaxis.setVerticalTickLabels(true);


    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setRange(0.0, 300.0);


    return result;
    }
    /**
    * Generates an random entry for a particular call made by time for every 1/4th of a second.
    *
    * @param e the action event.
    */
    public void actionPerformed(final ActionEvent e) {


    final double factor = 0.9 + 0.2*Math.random();
    this.lastValue = this.lastValue * factor;


    final Millisecond now = new Millisecond();
    this.series.add(new Millisecond(), this.lastValue);


    System.out.println("Current Time in Milliseconds = " + now.toString()+", Current Value : "+this.lastValue);
    }


    /**
    * Starting point for the dynamic graph application.
    *
    * @param args ignored.
    */
    public static void main(final String[] args) {


    final DynamicLineAndTimeSeriesChart demo = new DynamicLineAndTimeSeriesChart("Dynamic Line And TimeSeries Chart");
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);


    }


    }


    I want to append the above java lines in above code such that the socket should read only once i.e; in public static void main(final String[] args) and the buffered reader method along with while loop must be in public void actionPerformed(final ActionEvent e).
    try {


    Socket skt = new Socket("192.168.1.67", 5001);
    //for(;;)
    {
    //Socket skt = new Socket("192.168.1.67", 5001);
    BufferedReader in = new BufferedReader(new
    InputStreamReader(skt.getInputStream()));
    while (!in.ready()) {}
    int value;
    while((value = in.read()) != -1)
    {

    }
    in.close();
    }
    }
    catch(Exception e) {}

Check out some similar questions!

What all topics comes under advance java?what is framework how it is related to java? [ 0 Answers ]

I want to know about the topics related to advance java?and how the framework likke struts and hibernate realted to each other?what are there uses?

I am new to java GUI and multiple classes, I have knowledge of core java. I have [ 0 Answers ]

Sir, I am new to java GUI and multiple classes, I have knowledge of core java. I have to call a rest client from my net beans project give values to it and receive it's output in the same project. Please suggest me what I need to study and what to do.

Java netbeans program- Connection between java and mysql,How to conn [ 0 Answers ]

which I wrote from a book but when I run it, it shows exception please give me the code to connect jlistbox to database when I click on btn1. btn coding should search "name" in database and shows all the names in listbox my coding: here-- r1,r2,r3 are radio btns and l1,l2,l3 are labels,...

Query? [ 1 Answers ]

Can a query have more than 2 interpretations?

DNS Query Query. A Query about DNS Queries... [ 12 Answers ]

I am a software developer, I don’t know much about networks. I have a working network but with one weird (well to me it’s weird) problem. If you can offer any insight I’ll be very grateful! <!--- Image Attachment Below (I couldn't find a way to paste it here in the editor :-( ) ---> ...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.