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 GUI; import DAO.CarDAO; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot3D; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.util.Rotation; /** * * @author marwen */ public class CarsStats extends javax.swing.JFrame { /** * Creates new form Vehicule */ public CarsStats() { initComponents(); DefaultPieDataset chartData = new DefaultPieDataset(); CarDAO carDao = new CarDAO(); chartData.setValue("Bonne", carDao.findBonneCarCount()); // restart session carDao = new CarDAO(); chartData.setValue("Moyenne", carDao.findMoyenneCarCount()); // restart session carDao = new CarDAO(); chartData.setValue("Mauvaise", carDao.findMauvaiseCarCount()); // This will create the dataset PieDataset dataset = (PieDataset) chartData; // based on the dataset we create the chart JFreeChart chart = createChart(dataset, "Cars stats"); // we put the chart into a panel ChartPanel chartPanel = new ChartPanel(chart); // default size chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); // add it to our application setContentPane(chartPanel); } /** * Creates a chart */ private JFreeChart createChart(PieDataset dataset, String title) { JFreeChart chart = ChartFactory.createPieChart3D(title, // chart title dataset, // data true, // include legend true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); return chart; } /** * 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(); VehiculesBT = new javax.swing.JButton(); reparationBT = new javax.swing.JButton(); carburantBT = new javax.swing.JButton(); magasinsBT = new javax.swing.JButton(); parametresBT = new javax.swing.JButton(); welcomeMrLB = new javax.swing.JLabel(); signOutBT = new javax.swing.JButton(); addCarBT = new javax.swing.JButton(); carsStateBT = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); VehiculesBT.setText("Vehicules"); VehiculesBT.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { VehiculesBTActionPerformed(evt); } }); reparationBT.setText("Reparations"); carburantBT.setText("Carburant"); magasinsBT.setText("Magasins"); parametresBT.setText("Parametres"); welcomeMrLB.setText("Bienvenue MR "); signOutBT.setText("Deconnexion"); addCarBT.setText("Ajouter vehicule"); carsStateBT.setText("Etat des vehicules dans une anne"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(addCarBT).addGap(18, 18, 18) .addComponent(carsStateBT)) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(VehiculesBT) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(reparationBT) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(carburantBT) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(magasinsBT) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(parametresBT) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(welcomeMrLB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(signOutBT))) .addContainerGap(20, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(VehiculesBT).addComponent(reparationBT).addComponent(carburantBT) .addComponent(magasinsBT).addComponent(parametresBT).addComponent(welcomeMrLB) .addComponent(signOutBT)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addCarBT).addComponent(carsStateBT)) .addGap(0, 244, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent( jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); pack(); }// </editor-fold>//GEN-END:initComponents private void VehiculesBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VehiculesBTActionPerformed // TODO add your handling code here: }//GEN-LAST:event_VehiculesBTActionPerformed /** * @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(CarsStats.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(CarsStats.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(CarsStats.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(CarsStats.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new CarsStats().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton VehiculesBT; private javax.swing.JButton addCarBT; private javax.swing.JButton carburantBT; private javax.swing.JButton carsStateBT; private javax.swing.JPanel jPanel1; private javax.swing.JButton magasinsBT; private javax.swing.JButton parametresBT; private javax.swing.JButton reparationBT; private javax.swing.JButton signOutBT; private javax.swing.JLabel welcomeMrLB; // End of variables declaration//GEN-END:variables }