[nbusers] how to add JChart2D

  • From: "waghmalemahesh" < >
  • To:
  • Subject: [nbusers] how to add JChart2D
  • Date: Fri, 02 Nov 2012 06:05:15 -0400

I am struggling for adding Jchart2D on Jpanel on netbeans. Please check 
following code for:-


package graph;

import info.monitorenter.gui.chart.Chart2D;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.gui.chart.traces.Trace2DLtd;

import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JFrame;

public class gr extends javax.swing.JFrame
{
Chart2D chart = new Chart2D();
final ITrace2D trace = new Trace2DLtd(200); 

    public gr() 
    {
        initComponents();
        chart.addTrace(trace);
        trace.setColor(Color.RED);
        grpanel.add(chart);
        grpanel.setVisible(true); 
        Timer timer = new Timer(true);
        TimerTask task = new TimerTask()
        {
            private double m_y = 0;
            private long m_starttime = System.currentTimeMillis();
            public void run() 
            {
                double rand = Math.random();
                boolean add = (rand >= 0.5) ? true : false;
                this.m_y = (add) ? this.m_y + Math.random() : this.m_y - 
Math.random();
                trace.addPoint(((double) System.currentTimeMillis() - 
this.m_starttime), this.m_y);
             }
         };
   
      timer.schedule(task, 1000, 20);
      }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        grpanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout grpanelLayout = new 
javax.swing.GroupLayout(grpanel);
        grpanel.setLayout(grpanelLayout);
        grpanelLayout.setHorizontalGroup(
            
grpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 547, Short.MAX_VALUE)
        );
        grpanelLayout.setVerticalGroup(
            
grpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 502, Short.MAX_VALUE)
        );

        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(67, 67, 67)
                .addComponent(grpanel, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(585, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(grpanel, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(251, Short.MAX_VALUE))
        );

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

    /**
     * @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(gr.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        } catch (InstantiationException ex) {
            
java.util.logging.Logger.getLogger(gr.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        } catch (IllegalAccessException ex) {
            
java.util.logging.Logger.getLogger(gr.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            
java.util.logging.Logger.getLogger(gr.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        }
        //</editor-fold>
    JFrame frame = new JFrame("MinimalDynamicChart");
    frame.setVisible(true);
    frame.setSize(400,300);
    }
    // Variables declaration - do not modify
    private javax.swing.JPanel grpanel;
    // End of variables declaration
}


But when i try to add chart on JFrame then it works without error....
so please suggest me how to add it is on JPanel.






[nbusers] how to add JChart2D

waghmalemahesh 11/02/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close