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 Interface; /** * * @author USER */ import Finance.Apayer; import Heure.Maintenant; import Mapping.Netapayer; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.ui.RefineryUtilities; public class Graphe extends javax.swing.JFrame { /** * Creates new form Graphe */ Object[] idnetpaye; Object[] idemployer; Object[] datenetpaye; Object[] montantnet; //String ddebut= "2016/01/01"; //String dfin = "2020/12/31"; public Graphe() { initComponents(); Maintenant m = new Maintenant(); deb.setText(m.getDate()); fin.setText(m.getDate()); } /** * 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(); jSeparator1 = new javax.swing.JSeparator(); jButton1 = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); deb = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); fin = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel1.setText("Graphe"); jButton1.setText("Generer"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel2.setText("les montants des net payer en salaire"); jLabel3.setText("Entre :"); jLabel4.setText("et :"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSeparator1)) .addGroup(layout.createSequentialGroup().addGap(188, 188, 188).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jLabel3).addGap(18, 18, 18) .addComponent(deb, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addComponent(jLabel4).addGap(34, 34, 34) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE) .addComponent(fin)))) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) .addGroup(layout.createSequentialGroup().addGap(98, 98, 98).addComponent(jLabel2) .addContainerGap(100, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel1) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18).addComponent(jLabel2).addGap(46, 46, 46) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3).addComponent(deb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(fin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18).addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(170, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents public Graphe(String applicationTitle, String chartTitle) { super(applicationTitle); JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Annes", "Montant", createDataset(), PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(lineChart); chartPanel.setPreferredSize(new java.awt.Dimension(600, 400)); setContentPane(chartPanel); } private DefaultCategoryDataset createDataset() { Apayer p = new Apayer(); //String dateDebut = datedebut.getText(); //String dateFin = datefin.getText(); //int size = p.countNetPayer("2016/01/01","2020/12/31"); //Netapayer[] np = p.selectNetapayer("2016/01/01","2020/12/31"); int size = p.countNetPayer("2016/01/01", "2020/12/31"); Netapayer[] np = p.selectNetapayer("2016/01/01", "2020/12/31"); idnetpaye = new Object[size]; idemployer = new Object[size]; datenetpaye = new Object[size]; montantnet = new Object[size]; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < size; i++) { idnetpaye[i] = (Object) np[i].getIdnetpaye(); idemployer[i] = (Object) np[i].getIdemployer(); datenetpaye[i] = (Object) np[i].getDatenetpaye(); montantnet[i] = (Object) np[i].getMontantnet(); dataset.addValue((double) montantnet[i], "payer", datenetpaye[i].toString()); } //dataset.addValue(12000, "payer",datenetpaye.toString()); // dataset.addValue(190000, "payer", "2017/11/30"); //dataset.addValue(200000, "payer", "2018/11/30"); //dataset.addValue(154000, "payer", "2019/11/30"); //dataset.addValue(190000, "payer", "2020/11/30"); //dataset.addValue(178000, "payer", "2021/11/30"); //dataset.addValue(100000, "retenue", "2001"); //dataset.addValue(190000, "retenue", "2002"); //dataset.addValue(200000, "retenue", "2003"); //dataset.addValue(120000, "retenue", "2004"); //dataset.addValue(150000, "retenue", "2005"); //dataset.addValue( 300 , "schools" , "2006" ); return dataset; } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: Graphe chart = new Graphe("Graphe", "Les montants des net payer en salaire entre : " + deb.getText() + " et " + fin.getText() + ""); this.dispose(); chart.pack(); RefineryUtilities.centerFrameOnScreen(chart); chart.setVisible(true); // System.out.println(deb.getText() + fin.getText()); // System.out.println(ddebut + dfin); }//GEN-LAST:event_jButton1ActionPerformed /** * @param args the command line arguments */ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField deb; private javax.swing.JTextField fin; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JSeparator jSeparator1; // End of variables declaration//GEN-END:variables }