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 correcao; import java.awt.CardLayout; import java.awt.Color; import java.util.ArrayList; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author Aluno */ public class PanelCorrecao extends javax.swing.JPanel { /** * Creates new form PanelCorrecao */ ProvaOff p = new ProvaOff(); Corretor c = new Corretor(); double cont = 0; double soma = 0; ArrayList<Integer> resp = new ArrayList<Integer>(); public PanelCorrecao() { 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() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); panel = new javax.swing.JPanel(); setPreferredSize(new java.awt.Dimension(1024, 500)); jLabel1.setFont(new java.awt.Font("Roboto", 0, 24)); // NOI18N jLabel1.setForeground(new java.awt.Color(0, 0, 159)); jLabel1.setText("Prova corrigida com Sucesso!"); jLabel2.setFont(new java.awt.Font("Roboto", 0, 18)); // NOI18N jLabel2.setForeground(new java.awt.Color(0, 0, 159)); jLabel2.setText(" "); jButton1.setBackground(new java.awt.Color(0, 0, 159)); jButton1.setFont(new java.awt.Font("Roboto", 0, 11)); // NOI18N jButton1.setForeground(new java.awt.Color(240, 240, 240)); jButton1.setText("Corrigir Mais Provas"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setBackground(new java.awt.Color(0, 0, 159)); jButton2.setFont(new java.awt.Font("Roboto", 0, 11)); // NOI18N jButton2.setForeground(new java.awt.Color(240, 240, 240)); jButton2.setText("Mostrar Grficos"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setBackground(new java.awt.Color(0, 0, 159)); jButton3.setFont(new java.awt.Font("Roboto", 0, 11)); // NOI18N jButton3.setForeground(new java.awt.Color(240, 240, 240)); jButton3.setText("Mostrar resultado"); jButton3.setMaximumSize(new java.awt.Dimension(159, 23)); jButton3.setMinimumSize(new java.awt.Dimension(159, 23)); jButton3.setPreferredSize(new java.awt.Dimension(159, 23)); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel); panel.setLayout(panelLayout); panelLayout.setHorizontalGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 374, Short.MAX_VALUE)); panelLayout.setVerticalGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 213, Short.MAX_VALUE)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(108, 108, 108) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(105, 105, 105)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(334, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(jLabel2).addGap(410, 410, 410)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(jLabel1).addGap(339, 339, 339)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(427, 427, 427)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(316, 316, 316))))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(54, 54, 54).addComponent(jLabel1).addGap(18, 18, 18) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(36, 36, 36).addComponent(jLabel2).addGap(38, 38, 38) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: CardLayout card = (CardLayout) this.getParent().getLayout(); card.show(this.getParent(), "ProvaOff"); jButton3.setVisible(true); jLabel2.setVisible(false); p.resetStuff(); }//GEN-LAST:event_jButton1ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed jLabel2.setText("Questes acertadas: " + ProvaOff.getRespostasCorretas()); resp.add(ProvaOff.getRespostasCorretas()); jButton3.setVisible(false); jLabel2.setVisible(true); }//GEN-LAST:event_jButton3ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: final CategoryDataset dcd = createDataset(); //for (int i = 0 ; i<p.nome.size() ; i++) { // dcd.addValue(resp.get(i), "Questes acertadas", p.nome.get(i)); //} JFreeChart jc; jc = ChartFactory.createBarChart3D("Grfico de Aproveitamento da Turma", "Nome do aluno", "Questes Acertadas", dcd, PlotOrientation.VERTICAL, true, true, false); CategoryPlot plot = jc.getCategoryPlot(); plot.setRangeGridlinePaint(Color.black); CategoryItemRenderer rend = plot.getRenderer(); rend.setSeriesPaint(0, new Color(0, 0, 159)); rend.setSeriesPaint(1, new Color(18, 230, 3)); ChartFrame cf = new ChartFrame("Aproveitamento", jc, true); cf.setVisible(true); cf.setSize(700, 500); }//GEN-LAST:event_jButton2ActionPerformed public CategoryDataset createDataset() { double media = 0; final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); //dataset.setValue(c.getNumeroDeQuestoes(p.returnProva()), "Nmero de questes da prova", "Nmero de questes da prova"); for (int i = 0; i < p.nomeSize(); i++) { dataset.setValue(resp.get(i), "Questes acertadas do aluno " + p.getNome(i), p.getNome(i)); cont++; soma += resp.get(i); } media = soma / cont; dataset.setValue(media, "Media da turma", "Media"); return dataset; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel panel; // End of variables declaration//GEN-END:variables }