Java tutorial
/* * 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 ufmotionsuite; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; /** * * @author Gabrielle */ public class SpiralGraph extends javax.swing.JFrame { /** * Creates new form SpiralGraph */ double[] xCoord = new double[10000]; double[] yCoord = new double[10000]; double[] r = new double[10000]; int arrLength; double[] theta = new double[10000]; public void getData(double[] x, double[] y, int length, double[] theta1) { for (int i = 0; i < length; i++) { xCoord[i] = x[i]; yCoord[i] = y[i]; } arrLength = length; for (int i = 3; i < arrLength; i++) { //CHANGE TO BE DISTANCE FROM ORIGIN TO POINT r[i] = Math.sqrt(Math.pow(xCoord[i] - xCoord[2], 2.0) + Math.pow(yCoord[i] - yCoord[2], 2.0)); theta[i] = theta1[i]; System.out.println("R is: " + r[i]); System.out.println(" Theta is: " + theta[i]); } Graph(); } public SpiralGraph() { initComponents(); // Sets corner icon ImageIcon img = new ImageIcon( "C:/Users/Gabrielle/Documents/NetBeansProjects/UFMotionSuite/Resources/Images/Logo/icon.png"); this.setIconImage(img.getImage()); } public void Graph() { XYSeries series = new XYSeries("X vs Y"); for (int i = 0; i < arrLength; i++) { //System.out.println("Run"); series.add(theta[i], r[i]); } XYDataset dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart("Distance from Origin over Angle", "Theta", "R (Distance)", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, false, false); BufferedImage image = chart.createBufferedImage(600, 600); jLabel1.setIcon(new ImageIcon(image)); this.setSize(800, 800); } /** * 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() { jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 677, Short.MAX_VALUE) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents /** * @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(SpiralGraph.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(SpiralGraph.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(SpiralGraph.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(SpiralGraph.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 SpiralGraph().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables }