fork download
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.text.DecimalFormat;
  7. import java.util.Random;
  8.  
  9. import javax.swing.Timer;
  10. import javax.swing.JButton;
  11. import javax.swing.JFrame;
  12. import javax.swing.JPanel;
  13.  
  14. import org.jfree.chart.ChartFactory;
  15. import org.jfree.chart.ChartPanel;
  16. import org.jfree.chart.JFreeChart;
  17. import org.jfree.chart.axis.ValueAxis;
  18. import org.jfree.chart.plot.XYPlot;
  19. import org.jfree.data.time.Millisecond;
  20. import org.jfree.data.time.TimeSeries;
  21. import org.jfree.data.time.TimeSeriesCollection;
  22. import org.jfree.data.xy.XYDataset;
  23. import org.jfree.ui.ApplicationFrame;
  24. import org.jfree.ui.RefineryUtilities;
  25.  
  26. import com.phidgets.PhidgetException;
  27. import com.phidgets.TemperatureSensorPhidget;
  28. import com.phidgets.event.AttachEvent;
  29. import com.phidgets.event.AttachListener;
  30. import com.phidgets.event.DetachEvent;
  31. import com.phidgets.event.DetachListener;
  32. import com.phidgets.event.ErrorEvent;
  33. import com.phidgets.event.ErrorListener;
  34. import com.phidgets.event.TemperatureChangeEvent;
  35. import com.phidgets.event.TemperatureChangeListener;
  36.  
  37. /**
  38.  * An example to show how we can create a dynamic chart.
  39. */
  40. public class ChartMaker extends ApplicationFrame implements ActionListener {
  41.  
  42. /** The time series data. */
  43. private TimeSeries series;
  44.  
  45. /** The most recent value added. */
  46. private double lastValue = 0.0;
  47.  
  48. /** Timer to refresh graph after every second */
  49. private Timer timer = new Timer(1000, this);
  50.  
  51.  
  52. public ChartMaker(final String title) {
  53.  
  54. super(title);
  55. this.series = new TimeSeries("Temperature", Millisecond.class);
  56. final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
  57. final JFreeChart chart = createChart(dataset);
  58.  
  59. // 1/4 second
  60. timer.setInitialDelay(0);
  61.  
  62. //Sets background color of chart
  63. chart.setBackgroundPaint(Color.LIGHT_GRAY);
  64.  
  65. //Created JPanel to show graph on screen
  66. final JPanel content = new JPanel(new BorderLayout());
  67. content.setSize(new java.awt.Dimension(1290, 300));
  68.  
  69. //Created Chartpanel for chart area
  70. final ChartPanel chartPanel = new ChartPanel(chart);
  71.  
  72. JButton stopButton = new JButton("Stop");
  73. stopButton.addActionListener(new ActionListener() {
  74. public void actionPerformed(ActionEvent e) {
  75. pause();
  76. }
  77. });
  78.  
  79. chartPanel.add(stopButton);
  80.  
  81. JButton startButton = new JButton("Start");
  82. startButton.addActionListener(new ActionListener() {
  83. public void actionPerformed(ActionEvent e) {
  84. start();
  85. }
  86. });
  87.  
  88. chartPanel.add(startButton);
  89. content.add(chartPanel);
  90.  
  91. JFrame aframe = new JFrame();
  92. aframe.setSize(new java.awt.Dimension(800, 500));
  93. aframe.setContentPane(content);
  94. aframe.setVisible(true);
  95. aframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  96. }
  97.  
  98.  
  99.  
  100. /**
  101.   * Creates a Roast chart.
  102.   *
  103.   * @param dataset the dataset.
  104.   *
  105.   * @return A Roast Chart.
  106.   */
  107. private JFreeChart createChart(final XYDataset dataset) {
  108. final JFreeChart result = ChartFactory.createTimeSeriesChart(
  109. "RoastRadar",
  110. "Time",
  111. "Temperature (C°)",
  112. dataset,
  113. true,
  114. true,
  115. false
  116. );
  117. final XYPlot plot = result.getXYPlot();
  118.  
  119. plot.setBackgroundPaint(new Color(0xffffe0));
  120. plot.setDomainGridlinesVisible(true);
  121. plot.setDomainGridlinePaint(Color.lightGray);
  122. plot.setRangeGridlinesVisible(true);
  123. plot.setRangeGridlinePaint(Color.lightGray);
  124.  
  125. ValueAxis xaxis = plot.getDomainAxis();
  126. xaxis.setAutoRange(true);
  127.  
  128. //Domain axis would show data of 30 seconds for a time
  129. xaxis.setFixedAutoRange(30000.0);
  130. xaxis.setVerticalTickLabels(true);
  131.  
  132. ValueAxis yaxis = plot.getRangeAxis();
  133.  
  134.  
  135. //plot.setRenderer(this.datasetIndex, new StandardXYItemRenderer());
  136.  
  137. return result;
  138. }
  139.  
  140. /**
  141.   * Ticks sensor for temperature every second
  142.   *
  143.   * @param e the action event.
  144.   */
  145. public void actionPerformed(final ActionEvent e) {
  146. Random r = new Random();
  147. double randomValue = 0 + (400 - 0) * r.nextDouble();
  148.  
  149. this.series.add(new Millisecond(), randomValue);
  150.  
  151. //System.out.println("Current Time in Milliseconds = " + new Millisecond().toString()+", Current Value : "+this.lastValue);
  152. return;
  153. }
  154.  
  155. public void pause() {
  156. this.timer.stop();
  157. }
  158.  
  159. public void start() {
  160. timer = new Timer(1000, this);
  161. timer.start();
  162. }
  163.  
  164. /**
  165.   * Starting point for the dynamic graph application.
  166.   *
  167.   * @param args ignored.
  168.  
  169.   public static void main(final String[] args) {
  170.  
  171.   final ChartMaker demo = new ChartMaker("RoastRadar");
  172.   demo.pack();
  173.   RefineryUtilities.centerFrameOnScreen(demo);
  174.   demo.setVisible(true);
  175.   }*/
  176. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:40: error: class ChartMaker is public, should be declared in a file named ChartMaker.java
public class ChartMaker extends ApplicationFrame implements ActionListener {
       ^
Main.java:14: error: package org.jfree.chart does not exist
import org.jfree.chart.ChartFactory;
                      ^
Main.java:15: error: package org.jfree.chart does not exist
import org.jfree.chart.ChartPanel;
                      ^
Main.java:16: error: package org.jfree.chart does not exist
import org.jfree.chart.JFreeChart;
                      ^
Main.java:17: error: package org.jfree.chart.axis does not exist
import org.jfree.chart.axis.ValueAxis;
                           ^
Main.java:18: error: package org.jfree.chart.plot does not exist
import org.jfree.chart.plot.XYPlot;
                           ^
Main.java:19: error: package org.jfree.data.time does not exist
import org.jfree.data.time.Millisecond;
                          ^
Main.java:20: error: package org.jfree.data.time does not exist
import org.jfree.data.time.TimeSeries;
                          ^
Main.java:21: error: package org.jfree.data.time does not exist
import org.jfree.data.time.TimeSeriesCollection;
                          ^
Main.java:22: error: package org.jfree.data.xy does not exist
import org.jfree.data.xy.XYDataset;
                        ^
Main.java:23: error: package org.jfree.ui does not exist
import org.jfree.ui.ApplicationFrame;
                   ^
Main.java:24: error: package org.jfree.ui does not exist
import org.jfree.ui.RefineryUtilities;
                   ^
Main.java:26: error: package com.phidgets does not exist
import com.phidgets.PhidgetException;
                   ^
Main.java:27: error: package com.phidgets does not exist
import com.phidgets.TemperatureSensorPhidget;
                   ^
Main.java:28: error: package com.phidgets.event does not exist
import com.phidgets.event.AttachEvent;
                         ^
Main.java:29: error: package com.phidgets.event does not exist
import com.phidgets.event.AttachListener;
                         ^
Main.java:30: error: package com.phidgets.event does not exist
import com.phidgets.event.DetachEvent;
                         ^
Main.java:31: error: package com.phidgets.event does not exist
import com.phidgets.event.DetachListener;
                         ^
Main.java:32: error: package com.phidgets.event does not exist
import com.phidgets.event.ErrorEvent;
                         ^
Main.java:33: error: package com.phidgets.event does not exist
import com.phidgets.event.ErrorListener;
                         ^
Main.java:34: error: package com.phidgets.event does not exist
import com.phidgets.event.TemperatureChangeEvent;
                         ^
Main.java:35: error: package com.phidgets.event does not exist
import com.phidgets.event.TemperatureChangeListener;
                         ^
Main.java:40: error: cannot find symbol
public class ChartMaker extends ApplicationFrame implements ActionListener {
                                ^
  symbol: class ApplicationFrame
Main.java:43: error: cannot find symbol
    private TimeSeries series;
            ^
  symbol:   class TimeSeries
  location: class ChartMaker
Main.java:107: error: cannot find symbol
    private JFreeChart createChart(final XYDataset dataset) {
                                         ^
  symbol:   class XYDataset
  location: class ChartMaker
Main.java:107: error: cannot find symbol
    private JFreeChart createChart(final XYDataset dataset) {
            ^
  symbol:   class JFreeChart
  location: class ChartMaker
Main.java:55: error: cannot find symbol
        this.series = new TimeSeries("Temperature", Millisecond.class);
                          ^
  symbol:   class TimeSeries
  location: class ChartMaker
Main.java:55: error: cannot find symbol
        this.series = new TimeSeries("Temperature", Millisecond.class);
                                                    ^
  symbol:   class Millisecond
  location: class ChartMaker
Main.java:56: error: cannot find symbol
        final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
              ^
  symbol:   class TimeSeriesCollection
  location: class ChartMaker
Main.java:56: error: cannot find symbol
        final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
                                                 ^
  symbol:   class TimeSeriesCollection
  location: class ChartMaker
Main.java:57: error: cannot find symbol
        final JFreeChart chart = createChart(dataset);
              ^
  symbol:   class JFreeChart
  location: class ChartMaker
Main.java:70: error: cannot find symbol
        final ChartPanel chartPanel = new ChartPanel(chart);
              ^
  symbol:   class ChartPanel
  location: class ChartMaker
Main.java:70: error: cannot find symbol
        final ChartPanel chartPanel = new ChartPanel(chart);
                                          ^
  symbol:   class ChartPanel
  location: class ChartMaker
Main.java:108: error: cannot find symbol
        final JFreeChart result = ChartFactory.createTimeSeriesChart(
              ^
  symbol:   class JFreeChart
  location: class ChartMaker
Main.java:108: error: cannot find symbol
        final JFreeChart result = ChartFactory.createTimeSeriesChart(
                                  ^
  symbol:   variable ChartFactory
  location: class ChartMaker
Main.java:117: error: cannot find symbol
        final XYPlot plot = result.getXYPlot();
              ^
  symbol:   class XYPlot
  location: class ChartMaker
Main.java:125: error: cannot find symbol
        ValueAxis xaxis = plot.getDomainAxis();
        ^
  symbol:   class ValueAxis
  location: class ChartMaker
Main.java:132: error: cannot find symbol
        ValueAxis yaxis = plot.getRangeAxis();
        ^
  symbol:   class ValueAxis
  location: class ChartMaker
Main.java:149: error: cannot find symbol
        this.series.add(new Millisecond(), randomValue);
                            ^
  symbol:   class Millisecond
  location: class ChartMaker
39 errors
stdout
Standard output is empty