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 bbank; import java.awt.Color; import java.util.Date; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author David */ public class QuantityTimeGraphWindow extends javax.swing.JFrame { /** * Creates new form QuantityTimeGraphWindow */ public static int SelectedItem; public QuantityTimeGraphWindow() { initComponents(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); BloodStock.collectGraphData(SelectedItem); String title = "Quantity vs Time Graph"; switch (SelectedItem) { case 0: title = "Quantity vs Time Graph for Blood type A"; for (int i = 0; i < BloodStock.QuantityGraph.size(); i++) { dataset.addValue(((double) BloodStock.QuantityGraph.get(i)), "", "" + ((Date) BloodStock.DateGraph.get(i)).getDate() + "/" + (((Date) BloodStock.DateGraph.get(i)).getMonth() + 1)); } break; case 1: title = "Quantity vs Time Graph for Blood type B"; for (int i = 0; i < BloodStock.QuantityGraph.size(); i++) { dataset.addValue(((double) BloodStock.QuantityGraph.get(i)), "", "" + ((Date) BloodStock.DateGraph.get(i)).getDate() + "/" + (((Date) BloodStock.DateGraph.get(i)).getMonth() + 1)); } break; case 2: title = "Quantity vs Time Graph for Blood type O"; for (int i = 0; i < BloodStock.QuantityGraph.size(); i++) { dataset.addValue(((double) BloodStock.QuantityGraph.get(i)), "", "" + ((Date) BloodStock.DateGraph.get(i)).getDate() + "/" + (((Date) BloodStock.DateGraph.get(i)).getMonth() + 1)); } break; } JFreeChart chart = ChartFactory.createLineChart(title, "Date", "Amount (litres)", dataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(Color.BLACK); ChartPanel chartpanel = new ChartPanel(chart); jPanel1.removeAll(); jPanel1.add(chartpanel); jPanel1.validate(); } /** * 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() { jPanel1 = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setLocation(new java.awt.Point(200, 50)); setPreferredSize(new java.awt.Dimension(800, 600)); setSize(new java.awt.Dimension(800, 600)); jPanel1.setBackground(new java.awt.Color(153, 153, 153)); jPanel1.setLayout(new java.awt.BorderLayout()); getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); 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(QuantityTimeGraphWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(QuantityTimeGraphWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(QuantityTimeGraphWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(QuantityTimeGraphWindow.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 QuantityTimeGraphWindow().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel jPanel1; // End of variables declaration//GEN-END:variables }