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 TelasBanzos; import Utilitarios.ConexaoBanco; import java.awt.Color; import java.awt.Toolkit; import java.util.HashMap; import javax.swing.JCheckBox; import javax.swing.JOptionPane; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRResultSetDataSource; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.view.JasperViewer; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; /** * * @author jejo */ public class TelaRelatorioDiadaSemana extends javax.swing.JFrame { ConexaoBanco conexao = new ConexaoBanco(); /** * Creates new form TelaNovoOrcamento */ public TelaRelatorioDiadaSemana() { initComponents(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(2, "3", "Domingo"); dataset.setValue(5, "3", "Segunda"); dataset.setValue(4, "3", "Tera"); dataset.setValue(7, "3", "Quarta"); dataset.setValue(6, "3", "Quinta"); dataset.setValue(2, "3", "Sexta"); dataset.setValue(4, "3", "Sbado"); JFreeChart chart = ChartFactory.createBarChart("Alunos matriculados por dia da semana", "Dia da semana", "Quantidade Alunos", dataset, PlotOrientation.VERTICAL, false, true, false); ChartPanel myChartPanel = new ChartPanel(chart, true); pnGraf.add(myChartPanel); //colocar cor nas barras CategoryPlot plot = chart.getCategoryPlot(); BarRenderer render = (BarRenderer) plot.getRenderer(); render.setSeriesPaint(0, Color.ORANGE); setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("BanzosIcon.png")));//para setar um icone na janela } /** * 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() { jLabel2 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); botaoGerarRelatorio = new javax.swing.JButton(); botaoCancelar = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); selectTodos = new javax.swing.JCheckBox(); jCheckBox2 = new javax.swing.JCheckBox(); jCheckBox3 = new javax.swing.JCheckBox(); jCheckBox4 = new javax.swing.JCheckBox(); jCheckBox5 = new javax.swing.JCheckBox(); jCheckBox6 = new javax.swing.JCheckBox(); jCheckBox7 = new javax.swing.JCheckBox(); jCheckBox8 = new javax.swing.JCheckBox(); jScrollBar1 = new javax.swing.JScrollBar(); jTextField1 = new javax.swing.JTextField(); pnGraf = new javax.swing.JPanel(); imprimirGraf = new javax.swing.JButton(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); jMenuItem3 = new javax.swing.JMenuItem(); jMenuItem4 = new javax.swing.JMenuItem(); jMenuItem5 = new javax.swing.JMenuItem(); jMenuItem6 = new javax.swing.JMenuItem(); jMenuItem7 = new javax.swing.JMenuItem(); jMenuItem8 = new javax.swing.JMenuItem(); jMenuItem9 = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JPopupMenu.Separator(); jMenu4 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu(); jMenuItem10 = new javax.swing.JMenuItem(); jMenuItem11 = new javax.swing.JMenuItem(); jMenuItem12 = new javax.swing.JMenuItem(); jSeparator2 = new javax.swing.JPopupMenu.Separator(); jMenu5 = new javax.swing.JMenu(); jMenu3 = new javax.swing.JMenu(); jMenuItem13 = new javax.swing.JMenuItem(); jMenuItem14 = new javax.swing.JMenuItem(); jMenuItem15 = new javax.swing.JMenuItem(); jMenuItem16 = new javax.swing.JMenuItem(); jMenuItem17 = new javax.swing.JMenuItem(); jMenuItem18 = new javax.swing.JMenuItem(); jMenu6 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Relatrios"); setMinimumSize(new java.awt.Dimension(1000, 700)); getContentPane().setLayout(null); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/botton_banzos_icon2.png"))); // NOI18N jLabel2.setMaximumSize(new java.awt.Dimension(500, 500)); jLabel2.setMinimumSize(new java.awt.Dimension(500, 500)); jLabel2.setPreferredSize(new java.awt.Dimension(500, 500)); getContentPane().add(jLabel2); jLabel2.setBounds(860, 10, 130, 110); jLabel5.setFont(new java.awt.Font("Tw Cen MT Condensed Extra Bold", 1, 36)); // NOI18N jLabel5.setText("Grfico de Alunos por Dia da Semana"); getContentPane().add(jLabel5); jLabel5.setBounds(150, 40, 590, 30); botaoGerarRelatorio.setBackground(new java.awt.Color(0, 0, 0)); botaoGerarRelatorio.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N botaoGerarRelatorio.setForeground(new java.awt.Color(255, 255, 255)); botaoGerarRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/table.png"))); // NOI18N botaoGerarRelatorio.setText("Gerar Grfico"); botaoGerarRelatorio.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { botaoGerarRelatorioActionPerformed(evt); } }); getContentPane().add(botaoGerarRelatorio); botaoGerarRelatorio.setBounds(50, 350, 140, 30); botaoCancelar.setBackground(new java.awt.Color(0, 0, 0)); botaoCancelar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N botaoCancelar.setForeground(new java.awt.Color(255, 255, 255)); botaoCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/cancel.png"))); // NOI18N botaoCancelar.setText("Cancelar"); getContentPane().add(botaoCancelar); botaoCancelar.setBounds(70, 560, 109, 30); jLabel6.setText("Dias da Semana"); getContentPane().add(jLabel6); jLabel6.setBounds(70, 120, 90, 30); selectTodos.setBackground(new java.awt.Color(255, 255, 255)); selectTodos.setSelected(true); selectTodos.setText("Todos"); getContentPane().add(selectTodos); selectTodos.setBounds(50, 160, 110, 23); jCheckBox2.setBackground(new java.awt.Color(255, 255, 255)); jCheckBox2.setSelected(true); jCheckBox2.setText("Domingo"); getContentPane().add(jCheckBox2); jCheckBox2.setBounds(50, 180, 110, 23); jCheckBox3.setBackground(new java.awt.Color(255, 255, 255)); jCheckBox3.setSelected(true); jCheckBox3.setText("Segunda"); getContentPane().add(jCheckBox3); jCheckBox3.setBounds(50, 200, 110, 23); jCheckBox4.setBackground(new java.awt.Color(255, 255, 255)); jCheckBox4.setSelected(true); jCheckBox4.setText("Tera"); getContentPane().add(jCheckBox4); jCheckBox4.setBounds(50, 220, 110, 23); jCheckBox5.setBackground(new java.awt.Color(255, 255, 255)); jCheckBox5.setSelected(true); jCheckBox5.setText("Quarta"); getContentPane().add(jCheckBox5); jCheckBox5.setBounds(50, 240, 100, 23); jCheckBox6.setBackground(new java.awt.Color(255, 255, 255)); jCheckBox6.setSelected(true); jCheckBox6.setText("Quinta"); getContentPane().add(jCheckBox6); jCheckBox6.setBounds(50, 260, 120, 23); jCheckBox7.setBackground(new java.awt.Color(255, 255, 255)); jCheckBox7.setSelected(true); jCheckBox7.setText("Sexta"); getContentPane().add(jCheckBox7); jCheckBox7.setBounds(50, 280, 110, 23); jCheckBox8.setBackground(new java.awt.Color(255, 255, 255)); jCheckBox8.setSelected(true); jCheckBox8.setText("Sabado"); getContentPane().add(jCheckBox8); jCheckBox8.setBounds(50, 300, 110, 23); getContentPane().add(jScrollBar1); jScrollBar1.setBounds(180, 150, 17, 180); jTextField1.setFocusable(false); jTextField1.setRequestFocusEnabled(false); getContentPane().add(jTextField1); jTextField1.setBounds(40, 150, 160, 180); pnGraf.setBackground(new java.awt.Color(255, 255, 255)); pnGraf.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); pnGraf.setAutoscrolls(true); getContentPane().add(pnGraf); pnGraf.setBounds(240, 150, 710, 440); imprimirGraf.setBackground(new java.awt.Color(0, 0, 0)); imprimirGraf.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N imprimirGraf.setForeground(new java.awt.Color(255, 255, 255)); imprimirGraf.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/page_save.png"))); // NOI18N imprimirGraf.setText("Imprimir"); imprimirGraf.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { imprimirGrafActionPerformed(evt); } }); getContentPane().add(imprimirGraf); imprimirGraf.setBounds(70, 510, 110, 30); jMenuBar1.setBackground(new java.awt.Color(0, 0, 255)); jMenuBar1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); jMenu1.setText("Cadastrar"); jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/user.png"))); // NOI18N jMenuItem1.setText("Aluno"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu1.add(jMenuItem1); jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/user_gray.png"))); // NOI18N jMenuItem2.setText("Funcionrio"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu1.add(jMenuItem2); jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/page.png"))); // NOI18N jMenuItem3.setText("Aproveitamento"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu1.add(jMenuItem3); jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/music.png"))); // NOI18N jMenuItem4.setText("Instrumento"); jMenu1.add(jMenuItem4); jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/group_key.png"))); // NOI18N jMenuItem5.setText("Perfil de Acesso"); jMenu1.add(jMenuItem5); jMenuItem6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/money_add.png"))); // NOI18N jMenuItem6.setText("Planos de Matrcula"); jMenuItem6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem6ActionPerformed(evt); } }); jMenu1.add(jMenuItem6); jMenuItem7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/group_add.png"))); // NOI18N jMenuItem7.setText("Turmas"); jMenu1.add(jMenuItem7); jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/money.png"))); // NOI18N jMenuItem8.setText("Situao de Pagamento"); jMenu1.add(jMenuItem8); jMenuItem9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/user_orange.png"))); // NOI18N jMenuItem9.setText("Situao de Matrcula"); jMenu1.add(jMenuItem9); jMenu1.add(jSeparator1); jMenuBar1.add(jMenu1); jMenu4.setText("|"); jMenuBar1.add(jMenu4); jMenu2.setText("Emitir"); jMenuItem10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/page_attach.png"))); // NOI18N jMenuItem10.setText("Histrico Escolar"); jMenu2.add(jMenuItem10); jMenuItem11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/page_green.png"))); // NOI18N jMenuItem11.setText("Declarao"); jMenu2.add(jMenuItem11); jMenuItem12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/page_go.png"))); // NOI18N jMenuItem12.setText("Certificado"); jMenuItem12.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem12ActionPerformed(evt); } }); jMenu2.add(jMenuItem12); jSeparator2.setBackground(new java.awt.Color(0, 0, 0)); jSeparator2.setForeground(new java.awt.Color(0, 0, 0)); jMenu2.add(jSeparator2); jMenuBar1.add(jMenu2); jMenu5.setText("|"); jMenuBar1.add(jMenu5); jMenu3.setText("Relatrio"); jMenuItem13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/table.png"))); // NOI18N jMenuItem13.setText("Aproveitamento"); jMenu3.add(jMenuItem13); jMenuItem14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/group.png"))); // NOI18N jMenuItem14.setText("Turmas"); jMenu3.add(jMenuItem14); jMenuItem15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/group_gear.png"))); // NOI18N jMenuItem15.setText("Professores"); jMenu3.add(jMenuItem15); jMenuItem16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/music.png"))); // NOI18N jMenuItem16.setText("Alunos/Instrumentos"); jMenu3.add(jMenuItem16); jMenuItem17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/money_delete.png"))); // NOI18N jMenuItem17.setText("Alunos Inadimplentes"); jMenu3.add(jMenuItem17); jMenuItem18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/calendar.png"))); // NOI18N jMenuItem18.setText("Alunos/Dia"); jMenu3.add(jMenuItem18); jMenuBar1.add(jMenu3); jMenu6.setText("|"); jMenuBar1.add(jMenu6); setJMenuBar(jMenuBar1); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed }//GEN-LAST:event_jMenuItem1ActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jMenuItem2ActionPerformed private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jMenuItem3ActionPerformed private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jMenuItem6ActionPerformed private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jMenuItem12ActionPerformed private void botaoGerarRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoGerarRelatorioActionPerformed // SELECT TP.cod_turma_periodo, H.cod_turma_periodo, H.dia FROM tb_horario H //INNER JOIN rl_turma_periodo TP //ON TP.cod_turma_periodo = H.cod_turma_periodo conexao.conecta(); // String sql= "SELECT TP.cod_turma_periodo, H.cod_turma_periodo, H.dia FROM tb_horario H\n" + // "INNER JOIN rl_turma_periodo TP\n" + // "ON TP.cod_turma_periodo = H.cod_turma_periodo \n"; String sql = "SELECT H.dia AS Dia_Semana, COUNT(TA.matricula) AS Qdt_Alunos \n" + "FROM rl_aluno_turma TA\n" + "INNER JOIN rl_turma_periodo TP\n" + "ON TA.cod_turma_periodo = TP.cod_turma_periodo \n" + "INNER JOIN tb_horario H\n" + "ON TA.cod_turma_periodo = H.cod_turma_periodo \n" + "WHERE TP.ano = 2016 AND TP.semestre = 1\n" + "GROUP BY H.dia "; try { conexao.SelectSQL(sql); JRResultSetDataSource relatResult = new JRResultSetDataSource(conexao.rs); JasperPrint jpPrint = JasperFillManager.fillReport( "G:\\Projeto Final II\\PROTOTIPO FUNCIONAL\\ProjetoFinalII\\Relatorios\\AlunosPorDiasDaSemana.jasper", new HashMap(), relatResult); JasperViewer jv = new JasperViewer(jpPrint, true); jv.setSize(1200, 700); jv.setLocationRelativeTo(jv);//coloca a tela no meio jv.setVisible(true);//chama relatrio para visualizao jv.toFront();//seta o relatorio pra frente da aplicao } catch (JRException ex) { JOptionPane.showMessageDialog(null, "No foi possivel gerar o relatrio! " + ex.getMessage()); } }//GEN-LAST:event_botaoGerarRelatorioActionPerformed private void imprimirGrafActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imprimirGrafActionPerformed }//GEN-LAST:event_imprimirGrafActionPerformed /** * @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(TelaRelatorioDiadaSemana.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(TelaRelatorioDiadaSemana.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(TelaRelatorioDiadaSemana.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(TelaRelatorioDiadaSemana.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TelaRelatorioDiadaSemana().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton botaoCancelar; private javax.swing.JButton botaoGerarRelatorio; private javax.swing.JButton imprimirGraf; private javax.swing.JCheckBox jCheckBox2; private javax.swing.JCheckBox jCheckBox3; private javax.swing.JCheckBox jCheckBox4; private javax.swing.JCheckBox jCheckBox5; private javax.swing.JCheckBox jCheckBox6; private javax.swing.JCheckBox jCheckBox7; private javax.swing.JCheckBox jCheckBox8; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu3; private javax.swing.JMenu jMenu4; private javax.swing.JMenu jMenu5; private javax.swing.JMenu jMenu6; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem10; private javax.swing.JMenuItem jMenuItem11; private javax.swing.JMenuItem jMenuItem12; private javax.swing.JMenuItem jMenuItem13; private javax.swing.JMenuItem jMenuItem14; private javax.swing.JMenuItem jMenuItem15; private javax.swing.JMenuItem jMenuItem16; private javax.swing.JMenuItem jMenuItem17; private javax.swing.JMenuItem jMenuItem18; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JMenuItem jMenuItem4; private javax.swing.JMenuItem jMenuItem5; private javax.swing.JMenuItem jMenuItem6; private javax.swing.JMenuItem jMenuItem7; private javax.swing.JMenuItem jMenuItem8; private javax.swing.JMenuItem jMenuItem9; private javax.swing.JScrollBar jScrollBar1; private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JPopupMenu.Separator jSeparator2; private javax.swing.JTextField jTextField1; private javax.swing.JPanel pnGraf; private javax.swing.JCheckBox selectTodos; // End of variables declaration//GEN-END:variables }