Ayuda con Java Arduino y JFreechart

Iniciado por milnac, 6 Diciembre 2013, 20:46 PM

0 Miembros y 1 Visitante están viendo este tema.

milnac

buenas tardes compañeros. segui un tutorial de visualizar la data de arduino en java en netbeans,,corregi todos los errores pero no me ejecuta nada

Les paso el codigo

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package charts;

import Arduino.Arduino;
import gnu.io.SerialPortEvent;
import gnu.io.SerialPortEventListener;
import java.awt.Window;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.Grafica;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;



/**
*
* @author
*/
public class Timer555 extends javax.swing.JFrame {

   Arduino Arduino = new Arduino();
   SerialPortEventListener evento;
   private JFreeChart Grafica;
//    private JFreeChart Graphic;
   
   public Timer555() {
       this.evento = new SerialPortEventListener () {
           public void serialEvent(SerialPortEvent spe){
               
           }
       };
       initComponents();
   
       try {
       Arduino.ArduinoRX("COM20", 2000, 9600, evento);
   } catch (Exception ex){
       Logger.getLogger(Window.class.getName()).log(Level.SEVERE,null, ex);
   }
   final XYSeries Serie = new XYSeries("Timer555");
   final XYSeriesCollection Coleccion = new XYSeriesCollection();
    JFreeChart Grafica;
   
       Serie.add(0,0);
            Coleccion.addSeries(Serie);
            Grafica = ChartFactory.createXYLineChart("Voltaje vs Frecuencia", "Voltaje", "Frecuencia", Coleccion,
                    PlotOrientation.VERTICAL, true, true, false);
   
   }    
             
           
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
   private void initComponents() {

       jButton1 = new javax.swing.JButton();

       setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

       jButton1.setText("Grafica");
       jButton1.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               jButton1ActionPerformed(evt);
           }
       });

       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
       getContentPane().setLayout(layout);
       layout.setHorizontalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addGap(148, 148, 148)
               .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addContainerGap(126, Short.MAX_VALUE))
       );
       layout.setVerticalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addGap(104, 104, 104)
               .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addContainerGap(156, Short.MAX_VALUE))
       );

       pack();
   }// </editor-fold>                        

   private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
ChartPanel Panel = new ChartPanel(Grafica);
JFrame Ventana = new JFrame("JFreeChart");
Ventana.getContentPane().add(Panel);
Ventana.pack();
Ventana.setVisible(true);
Ventana.setDefaultCloseOperation(JFtame.EXIT_ON_CLOSE);
   }                                        

   /**
    * @param args the command line arguments
    */
   public static void main(String args[]) {
       /* Set the Nimbus look and feel */
       //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
       /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
        * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
       try {
           for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
               if ("Nimbus".equals(info.getName())) {
                   javax.swing.UIManager.setLookAndFeel(info.getClassName());
                   break;
               }
           }
       } catch (ClassNotFoundException ex) {
           java.util.logging.Logger.getLogger(Timer555.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       } catch (InstantiationException ex) {
           java.util.logging.Logger.getLogger(Timer555.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       } catch (IllegalAccessException ex) {
           java.util.logging.Logger.getLogger(Timer555.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       } catch (javax.swing.UnsupportedLookAndFeelException ex) {
           java.util.logging.Logger.getLogger(Timer555.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
       }
       //</editor-fold>

       /* Create and display the form */
       java.awt.EventQueue.invokeLater(new Runnable() {
           public void run() {
               new Timer555().setVisible(true);
           }
       });
   }

   // Variables declaration - do not modify                    
   private javax.swing.JButton jButton1;
   // End of variables declaration                  
}


Mi problema es en:

JFreeChart Grafica;
   
       Serie.add(0,0);
            Coleccion.addSeries(Serie);
            Grafica = ChartFactory.createXYLineChart("Voltaje vs Frecuencia", "Voltaje", "Frecuencia", Coleccion,
                    PlotOrientation.VERTICAL, true, true, false);


que queda sin ningun cambio en el compilador.

que es lo que le puede pasar??

Esperando su gran ayuda.

Gracias


egyware

#2
No veo en ninguna parte que estés guardando los valores a la colección, así que está bien que no te muestre nada.

PS: mira.. a esto me refiero.

Código (java) [Seleccionar]

this.evento = new SerialPortEventListener () {
     public void serialEvent(SerialPortEvent spe){
        // ??? Deberia ir algo acá ???
     }
};

milnac

Gracias egyware.

Mira, el tuto no manda nada en esa linea para poder guardar.

Dime, como haria para poder guardar esos elementos que me pide?? Y es que primera vez que trabajo en java y defrente con este proyecto.  :-(

milnac

mencion aparte, en
final XYSeries Serie = new XYSeries("Timer555");
    final XYSeriesCollection Coleccion = new XYSeriesCollection();
     JFreeChart Grafica;
   
        Serie.add(0,0);
             Coleccion.addSeries(Serie);
             Grafica = ChartFactory.createXYLineChart("Voltaje vs Frecuencia", "Voltaje", "Frecuencia", Coleccion,
                     PlotOrientation.VERTICAL, true, true, false);


En "Grafica", me dice que variable "Grafica" no esta usado o no se esta usando.