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 Panels; import java.awt.BorderLayout; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.DefaultButtonModel; import javax.swing.JButton; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PiePlot; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYDotRenderer; import org.jfree.chart.renderer.xy.XYSplineRenderer; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.xy.*; /** * * @author Marco */ public class FinanzPanel extends javax.swing.JPanel { /** * Creates new form FinanzPanel */ DetailContainer dc; private DefaultPieDataset pieDataset; private JFreeChart chart1; private ChartPanel chartPanel1; private double[][] A = { { 1, 2, 5 }, { 3, 4, 0 } }; //private DefaultXYDataset dataset; DefaultPieDataset dataset; private XYSplineRenderer renderer; NumberAxis xax; NumberAxis yax; //XYPlot plot; PiePlot plot; String projekt; String name; private ResultSet result; private Statement st; public FinanzPanel(DetailContainer dc) { this.dc = dc; initComponents(); dataset = new DefaultPieDataset(); ; // //dataset.addSeries("xy", A); // dataset.setValue("One", new Double(43.2)); // dataset.setValue("Two", new Double(10.0)); renderer = new XYSplineRenderer(); //// xax = new NumberAxis("x"); //// yax = new NumberAxis("y"); plot = new PiePlot(dataset); // //plot = new XYPlot(dataset,xax,yax, renderer); chart1 = new JFreeChart(plot); chartPanel1 = new ChartPanel(chart1); chartPanel1.setMouseWheelEnabled(true); // this.jPanel1.setLayout(new java.awt.BorderLayout()); this.jPanel1.add(chartPanel1); this.jButton1.setModel(new DefaultButtonModel()); // this.add(new JButton("back"), BorderLayout.SOUTH ); this.validate(); } public void setName(String name) { this.name = name; } public void callDb() { try { st = this.dc.getOracleConnector().dbcon.createStatement(); result = st.executeQuery("select * from finanzplan where IDFinPlan=" + name + ""); while (result.next()) { System.out.println("Test:" + result.getInt("geplant")); dataset.setValue("GEPLANT", new Double(result.getFloat("GEPLANT"))); dataset.setValue("VORHANDEN", new Double(result.getFloat("VORHANDEN"))); } plot = new PiePlot(dataset); chart1 = new JFreeChart(plot); chartPanel1 = new ChartPanel(chart1); chartPanel1.setMouseWheelEnabled(true); this.setLayout(new java.awt.BorderLayout()); this.add(chartPanel1, BorderLayout.CENTER); this.validate(); } catch (SQLException ex) { Logger.getLogger(MitarbeiterPanel.class.getName()).log(Level.SEVERE, null, ex); } } /** * 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() { jButton1 = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); setLayout(new java.awt.BorderLayout()); jButton1.setText("jButton1"); add(jButton1, java.awt.BorderLayout.PAGE_END); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400, Short.MAX_VALUE)); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 277, Short.MAX_VALUE)); add(jPanel1, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JPanel jPanel1; // End of variables declaration//GEN-END:variables }