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 edu.esprit.pi.gui.internalframes; import edu.esprit.pi.workshop.statistiques.BarChart; import edu.esprit.pi.workshop.statistiques.PieChart; import java.awt.BorderLayout; import javax.swing.JPanel; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryLabelPositions; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; /** * * @author Amine */ public class StatistiquesInternalFrame extends javax.swing.JInternalFrame { JFreeChart graphe; /** * Creates new form StatistiquesInternalFrame */ public StatistiquesInternalFrame() { initComponents(); } /** * 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() { objetsAffichebuttonGroup1 = new javax.swing.ButtonGroup(); BarbuttonGroup = new javax.swing.ButtonGroup(); directionbuttonGroup = new javax.swing.ButtonGroup(); camembergbuttonGroup = new javax.swing.ButtonGroup(); jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); stockjRadioButton1 = new javax.swing.JRadioButton(); quantitejRadioButton2 = new javax.swing.JRadioButton(); jLabel2 = new javax.swing.JLabel(); jPanel4 = new javax.swing.JPanel(); bar2DjRadioButton1 = new javax.swing.JRadioButton(); bar3djRadioButton2 = new javax.swing.JRadioButton(); jPanel5 = new javax.swing.JPanel(); camenberg2DRadioButton = new javax.swing.JRadioButton(); camemberg3DRadioButton = new javax.swing.JRadioButton(); genereGrapePieChartButton = new javax.swing.JButton(); genererGrapheBarChartjButton = new javax.swing.JButton(); graphiquejPanel = new javax.swing.JPanel(); setClosable(true); setTitle("Statistiques avec JfreeChart"); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Command Options")); jLabel1.setText("- Afficher la liste des articles par :"); objetsAffichebuttonGroup1.add(stockjRadioButton1); stockjRadioButton1.setText("Stock"); objetsAffichebuttonGroup1.add(quantitejRadioButton2); quantitejRadioButton2.setText("Quantite"); jLabel2.setText("- Choisir le type d'affichage : "); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Bar Chart")); BarbuttonGroup.add(bar2DjRadioButton1); bar2DjRadioButton1.setText("Bar 2D"); BarbuttonGroup.add(bar3djRadioButton2); bar3djRadioButton2.setText("Bar 3D"); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addGap(24, 24, 24) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(bar3djRadioButton2).addComponent(bar2DjRadioButton1)) .addContainerGap(103, Short.MAX_VALUE))); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(bar2DjRadioButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(bar3djRadioButton2))); jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Pie Chart")); camembergbuttonGroup.add(camenberg2DRadioButton); camenberg2DRadioButton.setText("Camemberg 2D"); camembergbuttonGroup.add(camemberg3DRadioButton); camemberg3DRadioButton.setText("Camemberg 3D"); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(camenberg2DRadioButton).addComponent(camemberg3DRadioButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addGap(15, 15, 15) .addComponent(camenberg2DRadioButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(camemberg3DRadioButton) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); genereGrapePieChartButton.setText("Gnrer Graphe pie chart"); genereGrapePieChartButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { genereGrapePieChartButtonActionPerformed(evt); } }); genererGrapheBarChartjButton.setText("Gnrer Graphe bar chart"); genererGrapheBarChartjButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { genererGrapheBarChartjButtonActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel2).addGap(0, 0, Short.MAX_VALUE)) .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(21, 21, 21) .addComponent(stockjRadioButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(quantitejRadioButton2)) .addComponent(jLabel1).addComponent(genererGrapheBarChartjButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addGroup(jPanel2Layout.createSequentialGroup().addGap(20, 20, 20) .addComponent(genereGrapePieChartButton).addGap(0, 0, Short.MAX_VALUE))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(23, 23, 23).addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(quantitejRadioButton2).addComponent(stockjRadioButton1)) .addGap(20, 20, 20).addComponent(jLabel2).addGap(18, 18, 18) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(genererGrapheBarChartjButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(genereGrapePieChartButton).addContainerGap(67, Short.MAX_VALUE))); graphiquejPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); javax.swing.GroupLayout graphiquejPanelLayout = new javax.swing.GroupLayout(graphiquejPanel); graphiquejPanel.setLayout(graphiquejPanelLayout); graphiquejPanelLayout.setHorizontalGroup(graphiquejPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 782, Short.MAX_VALUE)); graphiquejPanelLayout.setVerticalGroup(graphiquejPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 447, Short.MAX_VALUE)); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(graphiquejPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(graphiquejPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 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 genereGrapePieChartButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genereGrapePieChartButtonActionPerformed PieChart pieChart = new PieChart(); if (camenberg2DRadioButton.isSelected()) { graphe = pieChart.construireChart2D(); } else if (camemberg3DRadioButton.isSelected()) { graphe = pieChart.construireChart3D(); } ChartPanel chartPanel = new ChartPanel(graphe); graphiquejPanel.setLayout(new java.awt.BorderLayout()); graphiquejPanel.add(chartPanel, BorderLayout.CENTER); graphiquejPanel.validate(); }//GEN-LAST:event_genereGrapePieChartButtonActionPerformed private void genererGrapheBarChartjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genererGrapheBarChartjButtonActionPerformed BarChart barChart = new BarChart(); if (bar2DjRadioButton1.isSelected()) { graphe = barChart.construireChart2D(); } else if (bar3djRadioButton2.isSelected()) { graphe = barChart.construireChart3D(); } ChartPanel chartPanel = new ChartPanel(graphe); graphiquejPanel.setLayout(new java.awt.BorderLayout()); graphiquejPanel.add(chartPanel, BorderLayout.CENTER); graphiquejPanel.validate(); }//GEN-LAST:event_genererGrapheBarChartjButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup BarbuttonGroup; private javax.swing.JRadioButton bar2DjRadioButton1; private javax.swing.JRadioButton bar3djRadioButton2; private javax.swing.JRadioButton camemberg3DRadioButton; private javax.swing.ButtonGroup camembergbuttonGroup; private javax.swing.JRadioButton camenberg2DRadioButton; private javax.swing.ButtonGroup directionbuttonGroup; private javax.swing.JButton genereGrapePieChartButton; private javax.swing.JButton genererGrapheBarChartjButton; private javax.swing.JPanel graphiquejPanel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.ButtonGroup objetsAffichebuttonGroup1; private javax.swing.JRadioButton quantitejRadioButton2; private javax.swing.JRadioButton stockjRadioButton1; // End of variables declaration//GEN-END:variables }