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 practica2edd; import com.squareup.okhttp.FormEncodingBuilder; import com.squareup.okhttp.RequestBody; import java.util.StringTokenizer; import javax.swing.JOptionPane; import static practica2edd.Cola.getString; /** * * @author eliezer */ public class Matriz extends javax.swing.JFrame { /** * Creates new form Lista */ public Matriz() { 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(); jTextField1 = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jTextField2 = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jButton3 = new javax.swing.JButton(); jTextField3 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jButton4 = new javax.swing.JButton(); jTextField4 = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jButton5 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setFont(new java.awt.Font("Noto Sans", 1, 18)); // NOI18N jLabel1.setText("Matriz Dispersa"); jTextField1.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jLabel2.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jLabel2.setText("Escriba el correo electronico"); jButton1.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jButton1.setText("Agregar"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jButton2.setText("Borrar"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jTextField2.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jLabel3.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jLabel3.setText("Escriba el correo electronico"); jButton3.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jButton3.setText("Atras"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jTextField3.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jLabel4.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jLabel4.setText("Buscar por letra"); jButton4.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jButton4.setText("Buscar por letra"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jTextField4.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jLabel5.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jLabel5.setText("Buscar por dominio"); jButton5.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N jButton5.setText("Buscar por dominio"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jTextArea1.setColumns(20); jTextArea1.setRows(5); jTextArea1.setText( "--------------------------------------------Consola--------------------------------------"); jScrollPane1.setViewportView(jTextArea1); 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) .addGroup(layout.createSequentialGroup().addGap(190, 190, 190).addComponent(jLabel1) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel2)) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(layout.createSequentialGroup().addComponent(jLabel3) .addGap(42, 42, 42) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup().addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(40, 40, 40).addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(18, 18, 18).addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)).addGap(12, 12, 12).addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5).addComponent(jButton5)) .addGap(18, 18, 18).addComponent(jButton3).addGap(70, 70, 70)) .addGroup(layout .createSequentialGroup().addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE) .addContainerGap())))); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: Menu menu = new Menu(); menu.setVisible(true); this.setVisible(false); }//GEN-LAST:event_jButton3ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: // Texto boolean arroba = false; String a = jTextField1.getText(); int intIndex = a.indexOf("@"); if (intIndex != -1) { arroba = true; } else { arroba = false; } if (arroba == false) { JOptionPane.showMessageDialog(null, "Correo invalido"); } else { String dominio; String correo = ""; String letra = ""; String nombre = ""; correo = jTextField1.getText(); StringTokenizer tokens = new StringTokenizer(this.jTextField1.getText(), "@"); nombre = tokens.nextToken(); dominio = tokens.nextToken(); System.out.print(dominio); letra = Character.toString(nombre.charAt(0)); RequestBody formBody = new FormEncodingBuilder().add("dato", dominio).add("dato5", letra) .add("dato6", nombre).add("dato7", correo).add("dato2", "matriz").add("dato3", "agregarm") .build(); String r = getString("metodoWeb", formBody); System.out.println(r); jTextArea1.setText(jTextArea1.getText() + "\n" + r); jTextField1.setText(""); } }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: boolean arroba = false; String a = jTextField2.getText(); int intIndex = a.indexOf("@"); if (intIndex != -1) { arroba = true; } else { arroba = false; } if (arroba == false) { JOptionPane.showMessageDialog(null, "Correo invalido"); } else { String dominio; String correo = ""; String letra = ""; String nombre = ""; correo = jTextField2.getText(); StringTokenizer tokens = new StringTokenizer(this.jTextField2.getText(), "@"); nombre = tokens.nextToken(); dominio = tokens.nextToken(); System.out.print(dominio + letra + nombre + correo); letra = Character.toString(nombre.charAt(0)); RequestBody formBody = new FormEncodingBuilder().add("dato", dominio).add("dato5", letra) .add("dato6", nombre).add("dato7", correo).add("dato2", "matriz").add("dato3", "borrarm") .build(); String r = getString("metodoWeb", formBody); System.out.println(r); jTextArea1.setText(jTextArea1.getText() + "\n" + r); jTextField1.setText(""); } }//GEN-LAST:event_jButton2ActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: if (jTextField3.getText().equals("")) { JOptionPane.showMessageDialog(null, "Texto vacio"); } else { String letra; letra = jTextField3.getText(); RequestBody formBody = new FormEncodingBuilder().add("dato", "").add("dato6", "").add("dato7", "") .add("dato2", "matriz").add("dato3", "buscarl").add("dato5", letra).build(); String r = getString("metodoWeb", formBody); System.out.println(r); jTextArea1.setText(jTextArea1.getText() + "\n" + r); jTextField1.setText(""); } }//GEN-LAST:event_jButton4ActionPerformed private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed // TODO add your handling code here: if (jTextField4.getText().equals("")) { JOptionPane.showMessageDialog(null, "Texto vacio"); } else { String dominio; dominio = jTextField4.getText(); RequestBody formBody = new FormEncodingBuilder().add("dato", dominio).add("dato6", "").add("dato7", "") .add("dato2", "matriz").add("dato3", "buscard").add("dato5", "").build(); String r = getString("metodoWeb", formBody); System.out.println(r); jTextArea1.setText(jTextArea1.getText() + "\n" + r); jTextField1.setText(""); } }//GEN-LAST:event_jButton5ActionPerformed /** * @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(Matriz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Matriz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Matriz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Matriz.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 Matriz().setVisible(true); } }); } // 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.JButton jButton4; private javax.swing.JButton jButton5; 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.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; // End of variables declaration//GEN-END:variables }