Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package eleitor;
- // Bibliotecas
- import java.awt.Color;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- import javax.swing.JOptionPane;
- public class eleitor extends javax.swing.JFrame
- {
- // Instanciação
- Calendar cal = GregorianCalendar.getInstance();
- // Construtor
- public eleitor()
- {
- initComponents();
- config();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- btnCal = new javax.swing.JButton();
- pan1 = new javax.swing.JPanel();
- jLabel2 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- txtAnoAtu = new javax.swing.JTextField();
- txtAnoNas = new javax.swing.JFormattedTextField();
- pan2 = new javax.swing.JPanel();
- jLabel3 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel6 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- jLabel8 = new javax.swing.JLabel();
- txtIda = new javax.swing.JTextField();
- txtSem = new javax.swing.JTextField();
- txtHor = new javax.swing.JTextField();
- txtSeg = new javax.swing.JTextField();
- txtSitEle = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Perfil");
- setResizable(false);
- jLabel1.setFont(new java.awt.Font("Monotype Corsiva", 0, 36)); // NOI18N
- jLabel1.setForeground(new java.awt.Color(0, 153, 153));
- jLabel1.setText("PERFIL");
- btnCal.setFont(new java.awt.Font("Bauhaus 93", 1, 14)); // NOI18N
- btnCal.setText("Calcular");
- btnCal.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnCalActionPerformed(evt);
- }
- });
- pan1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14), new java.awt.Color(0, 0, 102))); // NOI18N
- jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel2.setForeground(new java.awt.Color(255, 0, 51));
- jLabel2.setText("Ano de Nascimento: ");
- jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel4.setForeground(new java.awt.Color(0, 102, 102));
- jLabel4.setText("Ano Atual: ");
- txtAnoAtu.setEditable(false);
- txtAnoAtu.setBackground(new java.awt.Color(51, 255, 255));
- try {
- txtAnoNas.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####")));
- } catch (java.text.ParseException ex) {
- ex.printStackTrace();
- }
- txtAnoNas.setText("Ano");
- javax.swing.GroupLayout pan1Layout = new javax.swing.GroupLayout(pan1);
- pan1.setLayout(pan1Layout);
- pan1Layout.setHorizontalGroup(
- pan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(pan1Layout.createSequentialGroup()
- .addGroup(pan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(pan1Layout.createSequentialGroup()
- .addGap(34, 34, 34)
- .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
- .addGap(18, 18, 18))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pan1Layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel4)
- .addGap(34, 34, 34)))
- .addGroup(pan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(txtAnoNas, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
- .addComponent(txtAnoAtu))
- .addGap(17, 17, 17))
- );
- pan1Layout.setVerticalGroup(
- pan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(pan1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(pan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(txtAnoNas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(pan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel4)
- .addComponent(txtAnoAtu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(39, Short.MAX_VALUE))
- );
- pan2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Situação", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14), new java.awt.Color(0, 204, 0))); // NOI18N
- jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel3.setForeground(new java.awt.Color(255, 102, 0));
- jLabel3.setText("Situação Eleitoral:");
- jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel5.setForeground(new java.awt.Color(0, 102, 204));
- jLabel5.setText("Idade: ");
- jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel6.setForeground(new java.awt.Color(0, 102, 204));
- jLabel6.setText("Horas:");
- jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel7.setForeground(new java.awt.Color(0, 102, 204));
- jLabel7.setText("Semanas: ");
- jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel8.setForeground(new java.awt.Color(0, 102, 204));
- jLabel8.setText("Segundos: ");
- txtIda.setEditable(false);
- txtIda.setBackground(new java.awt.Color(51, 255, 255));
- txtSem.setEditable(false);
- txtSem.setBackground(new java.awt.Color(51, 255, 255));
- txtHor.setEditable(false);
- txtHor.setBackground(new java.awt.Color(51, 255, 255));
- txtSeg.setEditable(false);
- txtSeg.setBackground(new java.awt.Color(51, 255, 255));
- txtSitEle.setEditable(false);
- txtSitEle.setBackground(new java.awt.Color(51, 255, 255));
- javax.swing.GroupLayout pan2Layout = new javax.swing.GroupLayout(pan2);
- pan2.setLayout(pan2Layout);
- pan2Layout.setHorizontalGroup(
- pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(pan2Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(pan2Layout.createSequentialGroup()
- .addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(pan2Layout.createSequentialGroup()
- .addGap(3, 3, 3)
- .addComponent(jLabel6))
- .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(18, 18, 18)
- .addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(txtIda, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
- .addComponent(txtHor))
- .addGap(18, 18, 18)
- .addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel8)
- .addComponent(jLabel7))
- .addGap(18, 18, 18)
- .addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(txtSem, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
- .addComponent(txtSeg)))
- .addGroup(pan2Layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addGap(18, 18, 18)
- .addComponent(txtSitEle, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pan2Layout.setVerticalGroup(
- pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(pan2Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel5)
- .addComponent(txtIda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel7)
- .addComponent(txtSem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(25, 25, 25)
- .addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(txtSeg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel6)
- .addComponent(txtHor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel8)))
- .addGap(31, 31, 31)
- .addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(txtSitEle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(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)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(pan1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(btnCal, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(6, 6, 6))
- .addGroup(layout.createSequentialGroup()
- .addGap(184, 184, 184)
- .addComponent(jLabel1))
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(pan2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(6, 6, 6)
- .addComponent(jLabel1)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addComponent(pan1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGap(29, 29, 29)
- .addComponent(btnCal, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(18, 18, 18)
- .addComponent(pan2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- // Método: Cálculo da idade (botão)
- private void btnCalActionPerformed(java.awt.event.ActionEvent evt) {
- try
- {
- // Capturando dados
- int ano_atual = cal.get(Calendar.YEAR); // Ano Atual
- int ano_nasc = Integer.parseInt(txtAnoNas.getText());// Ano Nascimento
- // Cálculos
- int ida = ano_atual - ano_nasc;
- int sem = ida * 48 ;
- int hor = ida * 365 * 24;
- int seg = hor * 60;
- // Saída de dados
- txtAnoAtu.setText(Integer.toString(ano_atual));
- txtIda.setText(Integer.toString(ida));
- txtSem.setText(Integer.toString(sem));
- txtHor.setText(Integer.toString(hor));
- txtSeg.setText(Integer.toString(seg));
- // Estrutura de decisão
- if( ida > 0 && ida < 16 )
- {
- txtSitEle.setText("Votação proibida");
- }
- else if( (ida >= 16 && ida < 18) || (ida >= 70) )
- {
- txtSitEle.setText("Votação opcional");
- }
- else
- {
- txtSitEle.setText("Votação obrigatória");
- }
- }
- catch (NumberFormatException e)
- {
- JOptionPane.showMessageDialog(this, "Preencha o campo corretamente");
- System.err.println(e);
- }
- }
- public static void main(String args[])
- {
- 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 | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex)
- {
- java.util.logging.Logger.getLogger(eleitor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- java.awt.EventQueue.invokeLater(() -> {
- new eleitor().setVisible(true);
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnCal;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabel8;
- private javax.swing.JPanel pan1;
- private javax.swing.JPanel pan2;
- private javax.swing.JTextField txtAnoAtu;
- private javax.swing.JFormattedTextField txtAnoNas;
- private javax.swing.JTextField txtHor;
- private javax.swing.JTextField txtIda;
- private javax.swing.JTextField txtSeg;
- private javax.swing.JTextField txtSem;
- private javax.swing.JTextField txtSitEle;
- // End of variables declaration
- // Método: Configurações
- private void config()
- {
- // Frame
- this.setLocationRelativeTo(null); // Tela no centro
- this.getContentPane().setBackground(Color.WHITE);// Tela em branco
- // Painel
- pan1.setBackground(Color.white);// Dados
- pan2.setBackground(Color.white);// Situação
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement