Problems with Method: chart.clone();

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Secundino
Newbie
Newbie
Posts: 5
Joined: Thu Jan 04, 2007 12:00 am

Problems with Method: chart.clone();

Post by Secundino » Mon Mar 12, 2007 5:15 pm

Hi,

I am using the teechart in my project and I am having problems with the method:

chart.clone ();

The problem happens when I want to open the same graph in a new Frame. To do that I am using the function

chart.clone ();

The Exception that is generated when I to open the charts Editor in main Frame and After that when I generate the new frame have the following error:


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.steema.teechart.Zoom.draw(Zoom.java:264)
at com.steema.teechart.Chart.doMouseMove(Chart.java:1171)
at com.steema.teechart.Chart.mouseMoved(Chart.java:1156)
at com.steema.teechart.TChart.processMouseMotionEvent(TChart.java:1203)
at java.awt.Component.processEvent(Component.java:5807)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4003)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


For development use NetBeans IDE 5.5 and TeeChart Java v1 Build 1.0.1.818

Please, help me, I need this solution in my project.

Thank you,

Ricardo.
ricardo@cose.fee.unicamp.br

The files Java used are below:


================Class 1 =========================
/*
* JFrameNewVisual.java
*
* Created on 28 de Fevereiro de 2007, 20:41
*/

import com.steema.teechart.*;
import com.steema.teechart.styles.*;
import javax.swing.*;
import java.awt.*;

/**
*
* @author ricardo
*/
public class JFrameNewVisual extends javax.swing.JFrame {
private TChart tChart = new TChart();
private TChart tChartClone = new TChart();
private double[][] mat;
private String[] legend;
private Commander jFrameTeeChartCommander;
private TChartAWTDemo tChartAWTDemo = new TChartAWTDemo();
//private JFrameNewVisual jFrameNewVisual;
/** Creates new form JFrameNewVisual */
public JFrameNewVisual() {
initComponents();
}


private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jToggleButton1 = new javax.swing.JToggleButton();
jSeparator1 = new javax.swing.JSeparator();
jToggleButton2 = new javax.swing.JToggleButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.X_AXIS));

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultados Graficos"));

jToggleButton1.setText("AddTChart");
jToggleButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});

jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
jSeparator1.setMaximumSize(new java.awt.Dimension(2, 32767));
jSeparator1.setMinimumSize(new java.awt.Dimension(2, 10));
jSeparator1.setPreferredSize(new java.awt.Dimension(2, 10));

jToggleButton2.setText("AddNewFrame");
jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton2ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jToggleButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jToggleButton2)
.addContainerGap(333, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToggleButton1)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jToggleButton2, javax.swing.GroupLayout.Alignment.LEADING)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE))
);
pack();
}// </editor-fold>

private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {


tChartClone.setChart((Chart) jFrameTeeChartCommander.getChart().clone());
tChartAWTDemo.setTeeChartFrame(tChartClone);
tChartAWTDemo.setVisible(true);

}

private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {

this.initTChart();

}


private void initTChart(){
tChart.setHeight(100);
tChart.setMinimumSize(new java.awt.Dimension(100, 100));
tChart.setPreferredSize(new java.awt.Dimension(100, 100));
tChart.setWidth(100);

mat = new double[15][24];
for(int i=0; i<3; i++){
Line lineSeries = new com.steema.teechart.styles.Line(tChart.getChart());
lineSeries.setClickableLine(false);
for(int j=0; j<24; j++){
lineSeries.add(10*Math.random());
}
}

tChart.getFooter().setVisible(true);
tChart.getHeader().setVisible(true);
tChart.getAspect().setView3D(false);
tChart.getLegend().setVisible(false);
tChart.setBackground(Color.WHITE);

jFrameTeeChartCommander = new Commander(tChart.getChart());
jFrameTeeChartCommander.setFloatable(false);
jFrameTeeChartCommander.setVisible(true);
jFrameTeeChartCommander.setRollover(true);

jPanel1.setLayout(new BorderLayout());
jPanel1.add(jFrameTeeChartCommander, BorderLayout.PAGE_START);
jPanel1.add(tChart, BorderLayout.CENTER);
jPanel1.repaint();
jPanel1.validate();

}


/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JFrameNewVisual().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JToggleButton jToggleButton1;
private javax.swing.JToggleButton jToggleButton2;
// End of variables declaration

}

=================Class 2 ========================

import java.awt.Frame;
import java.awt.AWTEvent;
import java.awt.event.WindowEvent;

import com.steema.teechart.TChart;
import com.steema.teechart.Commander;
import com.steema.teechart.styles.Bar;
import com.steema.teechart.Chart;
import java.awt.BorderLayout;

public class TChartAWTDemo extends Frame {
private javax.swing.JPanel jPanelTeeChartFrame;
private TChart tChart = new TChart();
private Commander jFrameTeeChartCommander;

public TChartAWTDemo() {

jPanelTeeChartFrame = new javax.swing.JPanel();

enableEvents(AWTEvent.WINDOW_EVENT_MASK);
setTitle("TeeChart for Java AWT Frame example");

setSize(600, 400);

}

protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
dispose();
}
}


public void setTeeChartFrame(TChart cht){

tChart = cht;
this.initCommander();
this.initGUI();

}

public void initCommander() {
jFrameTeeChartCommander = new Commander(tChart.getChart());
jFrameTeeChartCommander.setFloatable(false);
jFrameTeeChartCommander.setVisible(true);
}


public void initGUI() {
jPanelTeeChartFrame.setLayout(new BorderLayout());
jPanelTeeChartFrame.add(jFrameTeeChartCommander, BorderLayout.PAGE_START);
jPanelTeeChartFrame.add(tChart, BorderLayout.CENTER);
jPanelTeeChartFrame.repaint();
jPanelTeeChartFrame.validate();
this.add(jPanelTeeChartFrame);
}

}

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Mar 14, 2007 2:20 pm

Hi Secundino,

We have tested here using NetBeans 5.5 and JDK 1.6 and works fine. I've sent you the files we used. Could you please test if it works fine at your end?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Secundino
Newbie
Newbie
Posts: 5
Joined: Thu Jan 04, 2007 12:00 am

Please, send me the Source code used!

Post by Secundino » Thu Mar 15, 2007 11:48 am

Hi, Narcís.

Please, send me the files:

JFrameNewVisual.java
TChartAWTDemo.java

Referring the classes JFrameNewVisual and TChartAWTDemo .

I need this code to verify what you used to solve the problem!

I am awaiting! Thank you!

Ricardo.
ricardo@cose.fee.unicamp.br

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Mar 15, 2007 1:07 pm

Hi Ricardo,

We didn't make any change to the files you sent. We just compiled them under the environment I commented and sent you the compiled files so that you could test them at your end.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply