view.JFramePrincipal.java Source code

Java tutorial

Introduction

Here is the source code for view.JFramePrincipal.java

Source

/*
 * 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 view;

import com.jgoodies.looks.plastic.PlasticLookAndFeel;
import com.jgoodies.looks.plastic.md;
import com.jgoodies.looks.plastic.theme.BrownSugar;
import com.jgoodies.looks.plastic.theme.DarkStar;
import com.jgoodies.looks.plastic.theme.DesertBlue;
import com.jgoodies.looks.plastic.theme.ExperienceBlue;
import com.jgoodies.looks.plastic.theme.ExperienceRoyale;
import com.jgoodies.looks.plastic.theme.InvertedColorTheme;
import com.jgoodies.looks.plastic.theme.Silver;
import com.jgoodies.looks.plastic.theme.SkyBlue;
import com.jgoodies.looks.plastic.theme.SkyBluer;
import controller.ConnectionDB;
import java.awt.SystemColor;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/*
 *
 * @author Marco Antonio
 */

public class JFramePrincipal extends javax.swing.JFrame {

    ConnectionDB conexao = new ConnectionDB(); //  uma varivel global
    // ConectaBanco conecta = new ConectaBanco

    /**
     * Creates new form JFramePrincipal
     */

    public JFramePrincipal() {
        initComponents();
        conexao.conexao();// 

        // conecta.conexao();     

    }

    /**
     * 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() {

        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jFrame1 = new javax.swing.JFrame();
        jPanel1 = new javax.swing.JPanel();
        buttonMenuReq = new javax.swing.JButton();
        ButtonMenuDespesa = new javax.swing.JButton();
        buttonMenuUnidade = new javax.swing.JButton();
        buttonMenuUsuario = new javax.swing.JButton();
        buttonMenuSair = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuRim = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem1 = new javax.swing.JMenuItem();
        menuCadastro = new javax.swing.JMenu();
        menuItemUsuario = new javax.swing.JMenuItem();
        menuItemFornecedor = new javax.swing.JMenuItem();
        menuItemUnidade = new javax.swing.JMenuItem();
        menuItemDespesa = new javax.swing.JMenuItem();
        menuItemVeiculo = new javax.swing.JMenuItem();
        menuConsultas = new javax.swing.JMenu();
        menuDados = new javax.swing.JMenu();
        menuUtilitarios = new javax.swing.JMenu();
        menuConfig = new javax.swing.JMenu();
        menuAuditoria = new javax.swing.JMenu();
        menuRelatorios = new javax.swing.JMenu();
        menuAjuda = new javax.swing.JMenu();

        jMenu1.setText("jMenu1");

        jMenu2.setText("jMenu2");

        jMenu3.setText("jMenu3");

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(jFrame1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400, Short.MAX_VALUE));
        jFrame1Layout.setVerticalGroup(jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SISPRORIM - Sistema de Protocolo de Requisies");
        setBackground(new java.awt.Color(0, 51, 204));
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        buttonMenuReq.setToolTipText("Cadastro de Requisies");
        buttonMenuReq.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonMenuReqActionPerformed(evt);
            }
        });
        jPanel1.add(buttonMenuReq, new org.netbeans.lib.awtextra.AbsoluteConstraints(2, 2, 35, 35));

        ButtonMenuDespesa.setToolTipText("Cadastro de Despesas");
        ButtonMenuDespesa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonMenuDespesaActionPerformed(evt);
            }
        });
        jPanel1.add(ButtonMenuDespesa, new org.netbeans.lib.awtextra.AbsoluteConstraints(41, 2, 35, 35));

        buttonMenuUnidade.setToolTipText("Cadastro de Unidades");
        buttonMenuUnidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonMenuUnidadeActionPerformed(evt);
            }
        });
        jPanel1.add(buttonMenuUnidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 2, 35, 35));

        buttonMenuUsuario.setToolTipText("Cadastro de Usurios");
        buttonMenuUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonMenuUsuarioActionPerformed(evt);
            }
        });
        jPanel1.add(buttonMenuUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(119, 2, 35, 35));

        buttonMenuSair.setToolTipText("Sair");
        buttonMenuSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonMenuSairActionPerformed(evt);
            }
        });
        jPanel1.add(buttonMenuSair, new org.netbeans.lib.awtextra.AbsoluteConstraints(158, 2, 35, 35));

        jMenuBar1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        menuRim.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menuRim.setText("Requisies");
        menuRim.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        menuRim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuRimActionPerformed(evt);
            }
        });

        jMenuItem2.setText("RIM | RRP");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        menuRim.add(jMenuItem2);
        menuRim.add(jSeparator1);

        jMenuItem1.setText("Sair");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        menuRim.add(jMenuItem1);

        jMenuBar1.add(menuRim);

        menuCadastro.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menuCadastro.setText("Cadastro");
        menuCadastro.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        menuItemUsuario.setText("Usurio");
        menuItemUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemUsuarioActionPerformed(evt);
            }
        });
        menuCadastro.add(menuItemUsuario);

        menuItemFornecedor.setText("Fornecedor");
        menuCadastro.add(menuItemFornecedor);

        menuItemUnidade.setText("Unidade");
        menuItemUnidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemUnidadeActionPerformed(evt);
            }
        });
        menuCadastro.add(menuItemUnidade);

        menuItemDespesa.setText("Despesa");
        menuItemDespesa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemDespesaActionPerformed(evt);
            }
        });
        menuCadastro.add(menuItemDespesa);

        menuItemVeiculo.setText("Veculo");
        menuCadastro.add(menuItemVeiculo);

        jMenuBar1.add(menuCadastro);

        menuConsultas.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menuConsultas.setText("Consultas");
        menuConsultas.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jMenuBar1.add(menuConsultas);

        menuDados.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menuDados.setText("Dados");
        menuDados.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jMenuBar1.add(menuDados);

        menuUtilitarios
                .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menuUtilitarios.setText("Utilitrios");
        menuUtilitarios.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jMenuBar1.add(menuUtilitarios);

        menuConfig.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menuConfig.setText("Configuraes");
        menuConfig.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jMenuBar1.add(menuConfig);

        menuAuditoria.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menuAuditoria.setText("Auditoria");
        menuAuditoria.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jMenuBar1.add(menuAuditoria);

        menuRelatorios
                .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menuRelatorios.setText("Relatrios");
        menuRelatorios.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jMenuBar1.add(menuRelatorios);

        menuAjuda.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        menuAjuda.setText("Ajuda");
        menuAjuda.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jMenuBar1.add(menuAjuda);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(3, 3, 3)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(896, Short.MAX_VALUE)));
        layout.setVerticalGroup(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, 296, Short.MAX_VALUE)));

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void menuItemDespesaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemDespesaActionPerformed
        // TODO add your handling code here:
        JFrameDespesa formdespesa = new JFrameDespesa();
        formdespesa.setVisible(true);
    }//GEN-LAST:event_menuItemDespesaActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        conexao.desconectar();
        dispose();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        // lookandfeel muda de cores
        // biblioteca     looksdemo-2.3.1.jar
        //SkyBlue()
        //BrownSugar()
        //DarkStar()  
        //DesertGreen()
        //Silver()
        //ExperienceRoyale()
        try {
            PlasticLookAndFeel.setPlasticTheme(new DarkStar());
            try {
                UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
            } catch (InstantiationException ex) {
                Logger.getLogger(JFramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(JFramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
            } catch (UnsupportedLookAndFeelException ex) {
                Logger.getLogger(JFramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        SwingUtilities.updateComponentTreeUI(this);

        //JFramePrincipal.setBackground(SystemColor.BLACK);

    }//GEN-LAST:event_formWindowOpened

    private void menuItemUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemUsuarioActionPerformed
        // TODO add your handling code here:
        JFrameUsuario formusuario = new JFrameUsuario();
        formusuario.setVisible(true);
    }//GEN-LAST:event_menuItemUsuarioActionPerformed

    private void menuItemUnidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemUnidadeActionPerformed
        // TODO add your handling code here:
        JFrameUnidade formunidade = new JFrameUnidade();
        formunidade.setVisible(true);
    }//GEN-LAST:event_menuItemUnidadeActionPerformed

    private void menuRimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuRimActionPerformed

    }//GEN-LAST:event_menuRimActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        JFrameRim rim = new JFrameRim();
        rim.setVisible(true);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void buttonMenuSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMenuSairActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_buttonMenuSairActionPerformed

    private void buttonMenuReqActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMenuReqActionPerformed
        // TODO add your handling code here:
        JFrameRim rim = new JFrameRim();
        rim.setVisible(true);
    }//GEN-LAST:event_buttonMenuReqActionPerformed

    private void ButtonMenuDespesaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonMenuDespesaActionPerformed
        // TODO add your handling code here:
        JFrameDespesa formdespesa = new JFrameDespesa();
        formdespesa.setVisible(true);

    }//GEN-LAST:event_ButtonMenuDespesaActionPerformed

    private void buttonMenuUnidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMenuUnidadeActionPerformed
        // TODO add your handling code here:
        JFrameUnidade formunidade = new JFrameUnidade();
        formunidade.setVisible(true);
    }//GEN-LAST:event_buttonMenuUnidadeActionPerformed

    private void buttonMenuUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMenuUsuarioActionPerformed
        // TODO add your handling code here:
        JFrameUsuario formusuario = new JFrameUsuario();
        formusuario.setVisible(true);
    }//GEN-LAST:event_buttonMenuUsuarioActionPerformed

    /**
     * @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(JFramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JFramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JFramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JFramePrincipal.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 JFramePrincipal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonMenuDespesa;
    private javax.swing.JButton buttonMenuReq;
    private javax.swing.JButton buttonMenuSair;
    private javax.swing.JButton buttonMenuUnidade;
    private javax.swing.JButton buttonMenuUsuario;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenu menuAjuda;
    private javax.swing.JMenu menuAuditoria;
    private javax.swing.JMenu menuCadastro;
    private javax.swing.JMenu menuConfig;
    private javax.swing.JMenu menuConsultas;
    private javax.swing.JMenu menuDados;
    private javax.swing.JMenuItem menuItemDespesa;
    private javax.swing.JMenuItem menuItemFornecedor;
    private javax.swing.JMenuItem menuItemUnidade;
    private javax.swing.JMenuItem menuItemUsuario;
    private javax.swing.JMenuItem menuItemVeiculo;
    private javax.swing.JMenu menuRelatorios;
    private javax.swing.JMenu menuRim;
    private javax.swing.JMenu menuUtilitarios;
    // End of variables declaration//GEN-END:variables
}