Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JPanel.java to edit this template
- */
- package republicavalidacionec;
- /*
- * Nombre: Diego Villacreses
- * Fecha: 21 de enero del 2024
- * Asunto: Validacion de la Cedula Ecuatoriana con Interfaz Gráfica
- */
- import javax.swing.JOptionPane;
- import javax.swing.SwingUtilities;
- public class main extends javax.swing.JPanel {
- /**
- * Creates new form main
- */
- public main() {
- 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">
- private void initComponents() {
- jButton1 = new javax.swing.JButton();
- Bg = new javax.swing.JPanel();
- CarandoletImage = new javax.swing.JLabel();
- jPanel1 = new javax.swing.JPanel();
- IconEc = new javax.swing.JLabel();
- Title1 = new javax.swing.JLabel();
- Title2 = new javax.swing.JLabel();
- NoboaLogo = new javax.swing.JLabel();
- jPanel2 = new javax.swing.JPanel();
- jFieldCedula = new javax.swing.JTextField();
- jLabel1 = new javax.swing.JLabel();
- BtnValidar = new javax.swing.JButton();
- jButton1.setText("jButton1");
- Bg.setBackground(new java.awt.Color(204, 204, 204));
- CarandoletImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/attractive_129 (2).jpg"))); // NOI18N
- jPanel1.setBackground(new java.awt.Color(255, 255, 255));
- IconEc.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- IconEc.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Ecuador-Flag-icon (1).png"))); // NOI18N
- Title1.setFont(new java.awt.Font("Sitka Display", 1, 24)); // NOI18N
- Title1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- Title1.setText("VALIDACION DE LA CEDULA");
- Title2.setFont(new java.awt.Font("Sitka Display", 1, 24)); // NOI18N
- Title2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- Title2.setText("ECUATORIANA");
- NoboaLogo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- NoboaLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/nuevo-ecuador-fc2 (1).png"))); // NOI18N
- jPanel2.setBackground(new java.awt.Color(204, 204, 204));
- jFieldCedula.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jFieldCedulaActionPerformed(evt);
- }
- });
- jLabel1.setFont(new java.awt.Font("Segoe UI", 2, 18)); // NOI18N
- jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- jLabel1.setText("Ingrese su cedula ciudadanía:");
- BtnValidar.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
- BtnValidar.setText("Validar");
- BtnValidar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- BtnValidarActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
- jPanel2.setLayout(jPanel2Layout);
- jPanel2Layout.setHorizontalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jFieldCedula)
- .addComponent(BtnValidar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap())
- );
- jPanel2Layout.setVerticalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jFieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(BtnValidar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 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()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(NoboaLogo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(IconEc, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(Title1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(Title2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap())
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(IconEc)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(Title1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(Title2)
- .addGap(18, 18, 18)
- .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
- .addComponent(NoboaLogo)
- .addContainerGap())
- );
- javax.swing.GroupLayout BgLayout = new javax.swing.GroupLayout(Bg);
- Bg.setLayout(BgLayout);
- BgLayout.setHorizontalGroup(
- BgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(BgLayout.createSequentialGroup()
- .addContainerGap()
- .addComponent(CarandoletImage, javax.swing.GroupLayout.PREFERRED_SIZE, 594, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addContainerGap())
- );
- BgLayout.setVerticalGroup(
- BgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(BgLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(BgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(CarandoletImage, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
- .addContainerGap())
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
- this.setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(Bg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(Bg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- }// </editor-fold>
- private void jFieldCedulaActionPerformed(java.awt.event.ActionEvent evt) {
- // Nada se rellena
- }
- private void BtnValidarActionPerformed(java.awt.event.ActionEvent evt) {
- if (this.jFieldCedula.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "Estimado Usuario, recuerde que ese campo es obligatorio para validar su cédula");
- } else {
- String cedula = this.jFieldCedula.getText();
- // Verificar que la cédula tenga 10 dígitos
- if (cedula.length() != 10 || !cedula.matches("\\d+")) {
- JOptionPane.showMessageDialog(null, "Estimado Usuario, la cédula debe tener exactamente 10 dígitos numéricos", "Error", JOptionPane.ERROR_MESSAGE);
- return;
- }
- int digitoVerificador = Integer.parseInt(cedula.substring(9, 10));
- int acumPar = 0;
- int acumImPar = 0;
- for (int x = 0; x <= 8; x++) {
- int dato = Integer.parseInt(cedula.substring(x, x + 1));
- if (x % 2 == 0) {
- int opera = dato * 2;
- if (opera > 9) {
- opera = opera - 9;
- }
- acumPar = acumPar + opera;
- } else {
- acumImPar = acumImPar + dato;
- }
- }
- int total = acumPar + acumImPar;
- int calculoDigitoVerificador = (10 - (total % 10)) % 10;
- if (digitoVerificador == calculoDigitoVerificador) {
- JOptionPane.showMessageDialog(null, "Estimado Usuario, su cédula es correcta");
- } else {
- JOptionPane.showMessageDialog(null, "Estimado Usuario, su cédula es incorrecta", "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- javax.swing.JFrame frame = new javax.swing.JFrame("Validación de Cédula");
- frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
- main app = new main();
- frame.getContentPane().add(app);
- frame.setSize(1000, 400);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JPanel Bg;
- private javax.swing.JButton BtnValidar;
- private javax.swing.JLabel CarandoletImage;
- private javax.swing.JLabel IconEc;
- private javax.swing.JLabel NoboaLogo;
- private javax.swing.JLabel Title1;
- private javax.swing.JLabel Title2;
- private javax.swing.JButton jButton1;
- private javax.swing.JTextField jFieldCedula;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement