Sie sind auf Seite 1von 10

package editor; import javax.swing.JOptionPane; /* * To change this template, choose Tools * and open the template in the editor.

*/ /* * editor.java * * Created on 27/04/2011, 02:44:55 PM */ /** * * @author estudiante308 */ public class editorPrueva extends javax.swing.JFrame { /** Creates new form editor */ public editorPrueva() { 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() { jPanel1 = new javax.swing.JPanel(); jTextArea = new javax.swing.JTextField(); mayscula = new javax.swing.JButton(); minuscula = new javax.swing.JButton(); NumeroCaracteres = new javax.swing.JButton(); numero = new javax.swing.JTextField(); subcadena = new javax.swing.JButton(); reemplasarPalabra = new javax.swing.JButton(); posicionDeLetra = new javax.swing.JButton(); contarLosCararteresUnoPorUno = new javax.swing.JButton(); encritar = new javax.swing.JButton(); borrarPalabra = new javax.swing.JButton(); cortarPalabra = new javax.swing.JButton(); CopiarPalabra = new javax.swing.JButton(); InsertarPalabra = new javax.swing.JButton(); jButton13 = new javax.swing.JButton(); jButton14 = new javax.swing.JButton(); jButton15 = new javax.swing.JButton(); jButton16 = new javax.swing.JButton(); jButton17 = new javax.swing.JButton(); jButton18 = new javax.swing.JButton(); jButton19 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); Templates

setBackground(new java.awt.Color(0, 0, 0)); jPanel1.setBackground(new java.awt.Color(0, 0, 0)); jTextArea.setBackground(new java.awt.Color(204, 255, 255)); jTextArea.setFont(new java.awt.Font("Tahoma", 0, 24)); mayscula.setBackground(new java.awt.Color(0, 0, 0)); mayscula.setForeground(new java.awt.Color(255, 255, 255)); mayscula.setText("Pasar a Mayusculas"); mayscula.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { maysculaActionPerformed(evt); } }); minuscula.setBackground(new java.awt.Color(0, 0, 0)); minuscula.setForeground(new java.awt.Color(255, 255, 255)); minuscula.setText("Pasar a minusculas"); minuscula.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { minusculaActionPerformed(evt); } }); NumeroCaracteres.setBackground(new java.awt.Color(0, 0, 0)); NumeroCaracteres.setForeground(new java.awt.Color(255, 255, 255)); NumeroCaracteres.setText("Numero de Caracteres"); NumeroCaracteres.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { NumeroCaracteresActionPerformed(evt); } }); numero.setEditable(false); subcadena.setBackground(new java.awt.Color(0, 0, 0)); subcadena.setForeground(new java.awt.Color(255, 255, 255)); subcadena.setText("Sub Cadena"); subcadena.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { subcadenaActionPerformed(evt); } }); reemplasarPalabra.setBackground(new java.awt.Color(0, 0, 0)); reemplasarPalabra.setForeground(new java.awt.Color(255, 255, 255)); reemplasarPalabra.setText("Remplazar Palabra"); reemplasarPalabra.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { reemplasarPalabraActionPerformed(evt); } }); posicionDeLetra.setBackground(new java.awt.Color(0, 0, 0)); posicionDeLetra.setForeground(new java.awt.Color(255, 255, 255)); posicionDeLetra.setText("Posicion de la Letra"); posicionDeLetra.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) {

posicionDeLetraActionPerformed(evt); } }); contarLosCararteresUnoPorUno.setBackground(new java.awt.Color(0, 0, 0)); contarLosCararteresUnoPorUno.setForeground(new java.awt.Color(255, 255, 255)); contarLosCararteresUnoPorUno.setText("Contar los caracteres uno por uno" ); contarLosCararteresUnoPorUno.addActionListener(new java.awt.event.Action Listener() { public void actionPerformed(java.awt.event.ActionEvent evt) { contarLosCararteresUnoPorUnoActionPerformed(evt); } }); encritar.setBackground(new java.awt.Color(0, 0, 0)); encritar.setForeground(new java.awt.Color(255, 255, 255)); encritar.setText("Encriptar"); encritar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { encritarActionPerformed(evt); } }); borrarPalabra.setBackground(new java.awt.Color(0, 0, 0)); borrarPalabra.setForeground(new java.awt.Color(255, 255, 255)); borrarPalabra.setText("Borrar Palabra"); borrarPalabra.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { borrarPalabraActionPerformed(evt); } }); cortarPalabra.setBackground(new java.awt.Color(0, 0, 0)); cortarPalabra.setForeground(new java.awt.Color(255, 255, 255)); cortarPalabra.setText("Cortar Palabra"); cortarPalabra.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cortarPalabraActionPerformed(evt); } }); CopiarPalabra.setBackground(new java.awt.Color(0, 0, 0)); CopiarPalabra.setForeground(new java.awt.Color(255, 255, 255)); CopiarPalabra.setText("Copiar Palabra"); CopiarPalabra.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { CopiarPalabraActionPerformed(evt); } }); InsertarPalabra.setBackground(new java.awt.Color(0, 0, 0)); InsertarPalabra.setForeground(new java.awt.Color(255, 255, 255)); InsertarPalabra.setText("Insertar Palabra"); InsertarPalabra.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { InsertarPalabraActionPerformed(evt); } });

jButton13.setText("x"); jButton13.setToolTipText("Salir"); jButton13.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton13ActionPerformed(evt); } }); jButton14.setText("Invertir Palabra"); jButton14.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton14ActionPerformed(evt); } }); jButton15.setText("Contar Palabras"); jButton15.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton15ActionPerformed(evt); } }); jButton16.setText("Contar Consonantes"); jButton17.setText("Colocar palabra mayuscula"); jButton17.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton17ActionPerformed(evt); } }); jButton18.setText("Colocar minuscula la Palabra"); jButton18.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton18ActionPerformed(evt); } }); jButton19.setText("Encriptar palabra"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPan el1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment. LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(28, 28, 28) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel 1Layout.createSequentialGroup() .addComponent(jButton17) .addGap(18, 18, 18) .addComponent(jButton19) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.RELATED, 188, Short.MAX_VALUE) .addComponent(jButton13) .addGap(32, 32, 32))

.addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jButton16) .addGap(18, 18, 18) .addComponent(jButton18) .addContainerGap()) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(InsertarPalabra) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addComponent(jButton14) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addComponent(jButton15) .addGap(88, 88, 88)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(encritar) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.RELATED) .addComponent(borrarPalabra) .addGap(18, 18, 18) .addComponent(cortarPalabra) .addGap(19, 19, 19) .addComponent(CopiarPalabra) .addContainerGap()) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jTextArea, javax.swing.GroupLayout.DEFAULT _SIZE, 543, Short.MAX_VALUE) .addContainerGap()) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing. GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(subcadena) .addPreferredGap(javax.swing.LayoutStyle.Compone ntPlacement.UNRELATED) .addComponent(reemplasarPalabra) .addPreferredGap(javax.swing.LayoutStyle.Compone ntPlacement.UNRELATED) .addComponent(contarLosCararteresUnoPorUno)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(NumeroCaracteres) .addGap(18, 18, 18) .addComponent(numero, javax.swing.GroupLayout.PR EFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(mayscula) .addPreferredGap(javax.swing.LayoutStyle.Compone ntPlacement.UNRELATED) .addComponent(minuscula) .addPreferredGap(javax.swing.LayoutStyle.Compone ntPlacement.UNRELATED) .addComponent(posicionDeLetra))) .addContainerGap(124, Short.MAX_VALUE)))) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment. LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jTextArea, javax.swing.GroupLayout.PREFERRED_SIZE,

107, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(6, 6, 6) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(mayscula) .addComponent(minuscula) .addComponent(posicionDeLetra)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(NumeroCaracteres) .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE , javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(reemplasarPalabra) .addComponent(subcadena) .addComponent(contarLosCararteresUnoPorUno)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(encritar) .addComponent(borrarPalabra) .addComponent(CopiarPalabra) .addComponent(cortarPalabra)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(InsertarPalabra) .addComponent(jButton14) .addComponent(jButton15)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(jButton16) .addComponent(jButton18)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(jButton13) .addComponent(jButton17) .addComponent(jButton19)) .addGap(23, 23, 23)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP ane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING ) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.s wing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING ) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax .swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); pack(); }// </editor-fold> private void maysculaActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); cadena=cadena.toUpperCase(); jTextArea.setText(cadena); } private void minusculaActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); cadena=cadena.toLowerCase(); jTextArea.setText(cadena); } private void NumeroCaracteresActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); int longitud=cadena.length(); numero.setText(""+longitud); } private void subcadenaActionPerformed(java.awt.event.ActionEvent evt) { String datoA=JOptionPane.showInputDialog("posicion inicial"); int pos1=Integer.parseInt(datoA); String distancia=JOptionPane.showInputDialog("poscicion final"); int posfinal=Integer.parseInt(distancia); String cadena=jTextArea.getText(); String subcadena=cadena.substring(pos1,posfinal); JOptionPane.showMessageDialog(null,subcadena); } private void reemplasarPalabraActionPerformed(java.awt.event.ActionEvent evt ) { String cadena=jTextArea.getText(); String palabra=JOptionPane.showInputDialog(" escriba la palabra existente en el campo de texto"); String nuevap=JOptionPane.showInputDialog("nueva palabra"); cadena=cadena.replaceAll(palabra, nuevap); jTextArea.setText(cadena); } private void posicionDeLetraActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); String Palabra=JOptionPane.showInputDialog("letra"); int posicion=cadena.indexOf(Palabra);

JOptionPane.showMessageDialog(null,""+posicion); } private void contarLosCararteresUnoPorUnoActionPerformed(java.awt.event.Acti onEvent evt) { String cadena=jTextArea.getText(); for(int i=0;i<cadena.length();i++){ char c=cadena.charAt(i); JOptionPane.showMessageDialog(null,""+c); } } private void encritarActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); String cad=""; for(int k=0;k<cadena.length();k++){ char t=cadena.charAt(k); int asc=t; cad+=asc; } jTextArea.setText(cad); } private void borrarPalabraActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); int opc=0; while(opc==0){ String palabra=JOptionPane.showInputDialog(" escriba la palabra que dese a borrar"); String remplazo = ""; String resultado = ""; int a; do { jTextArea.setText(cadena); a = cadena.indexOf(palabra); if(a != -1){ resultado = cadena.substring(0, a); resultado = resultado + remplazo; resultado = resultado + cadena.substring(a + palabra.length()); cadena = resultado; } } while(a != -1); opc=JOptionPane.showConfirmDialog(null,"elija su opcion"); } } private void cortarPalabraActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); String palabra=JOptionPane.showInputDialog("palabra a cortar "); JOptionPane.showMessageDialog(null,"la palabras selecccionada aparecena al final");

String nuevaP=""; cadena=cadena.replaceAll(palabra,nuevaP); int posicion=cadena.indexOf(palabra); jTextArea.setText(cadena+" "+palabra); } private void CopiarPalabraActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); String palabra=JOptionPane.showInputDialog("palabra copiar"); JOptionPane.showMessageDialog(null,"la palabras selecccionada aparecena al final"); String nuevaP=""; cadena=cadena.replaceAll(palabra,palabra); int posicion=cadena.indexOf(palabra); jTextArea.setText(cadena+" "+palabra); } private void InsertarPalabraActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); String palabra=JOptionPane.showInputDialog("insertar despues de la palab ra"); String insertarP=JOptionPane.showInputDialog("palabra"); String nuevaP=palabra+" "+insertarP; cadena=cadena.replaceAll(palabra,nuevaP); jTextArea.setText(cadena); } private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {

} private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) { String cadena=jTextArea.getText(); String palabra=JOptionPane.showInputDialog("escribir palabra ke desea p asar a mayuscula"); palabra=palabra.toUpperCase(); jTextArea.setText(cadena+" "+palabra); } private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: }

/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new editorPrueva().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton CopiarPalabra; private javax.swing.JButton InsertarPalabra; private javax.swing.JButton NumeroCaracteres; private javax.swing.JButton borrarPalabra; private javax.swing.JButton contarLosCararteresUnoPorUno; private javax.swing.JButton cortarPalabra; private javax.swing.JButton encritar; private javax.swing.JButton jButton13; private javax.swing.JButton jButton14; private javax.swing.JButton jButton15; private javax.swing.JButton jButton16; private javax.swing.JButton jButton17; private javax.swing.JButton jButton18; private javax.swing.JButton jButton19; private javax.swing.JPanel jPanel1; private javax.swing.JTextField jTextArea; private javax.swing.JButton mayscula; private javax.swing.JButton minuscula; private javax.swing.JTextField numero; private javax.swing.JButton posicionDeLetra; private javax.swing.JButton reemplasarPalabra; private javax.swing.JButton subcadena; // End of variables declaration }

Das könnte Ihnen auch gefallen