RutherfordScattering.GraphViewPanel.java Source code

Java tutorial

Introduction

Here is the source code for RutherfordScattering.GraphViewPanel.java

Source

/*
 * 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 RutherfordScattering;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.annotations.XYAnnotation;
import org.jfree.chart.annotations.XYDrawableAnnotation;
import org.jfree.chart.annotations.XYPointerAnnotation;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author Geonmo
 */
public class GraphViewPanel extends ChartPanel {
    private int bin_count = 0;
    XYSeries s;
    XYSeriesCollection data;
    JFreeChart chart;

    public GraphViewPanel(JFreeChart chart) {
        super(chart);
        s = new XYSeries("Distance between alpha-nucleus");
        data = new XYSeriesCollection();
        data.addSeries(s);
        //this.chart = ChartFactory.createXYLineChart("Distance between","Time","Distance",data,PlotOrientation.VERTICAL,true,true,false);        
    }

    public void FillValue(double distance) {
        bin_count = bin_count + 1;
        this.s.add(bin_count, distance);
    }

    public JFreeChart getResultChart() {
        this.chart = ChartFactory.createXYLineChart("Distance between", "Time", "Distance", data,
                PlotOrientation.VERTICAL, true, true, false);
        return this.chart;
    }

    public void paintComponent(Graphics g2) {
        super.paintComponent(g2);
        this.setChart(getResultChart());

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0,
                400, Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
                Short.MAX_VALUE));
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}