/*
*2 marzo 2011
*/
package Logica;
/**
*
* @author Administrador
*/
public class Proceso {
private String cad;
public String getCad() {
return cad;
}
public void setCad(String cad) {
this.cad = cad;
}
public Proceso() {
cad=null;
}
public int hallarPalabras()
{
int aux=1;
int tam=cad.length();
if(cad==null)
aux=0;
else
for(int i=0; i<tam; i++)
if(cad.charAt(i)== ' '&& cad.charAt(i-1)!= ' '&& cad.charAt(i+1)!= ' '&& i+1<tam && i-1>=0)
aux+=1;
return aux;
}
public String imprimirSE()
{
String aux="";
int tam=cad.length();
for(int i=0; i<tam; i++)
if(cad.charAt(i)!= ' ')
aux+=cad.charAt(i);
return aux;
}
public String imprimirSV()
{
String aux="";
int tam=cad.length();
for(int i=0; i<tam; i++)
{ if(cad.charAt(i)== 'a'||cad.charAt(i)== 'A'||
cad.charAt(i)== 'e'||cad.charAt(i)== 'E'||
cad.charAt(i)== 'i'||cad.charAt(i)== 'I'||
cad.charAt(i)== 'o'||cad.charAt(i)== 'O'||
cad.charAt(i)== 'u'||cad.charAt(i)== 'U')
aux+=' ';
else
aux+=cad.charAt(i);
}
return aux;
}
public String imprimirSL()
{
String aux="";
int tam=cad.length();
for(int i=0; i<tam; i++)
{ if(cad.charAt(i)== 'a'||cad.charAt(i)== 'A'||
cad.charAt(i)== 'e'||cad.charAt(i)== 'E'||
cad.charAt(i)== 'i'||cad.charAt(i)== 'I'||
cad.charAt(i)== 'o'||cad.charAt(i)== 'O'||
cad.charAt(i)== 'u'||cad.charAt(i)== 'U')
aux+=cad.charAt(i);
else
aux+=' ';
}
return aux;
}
public String imprimirSLV()
{
String aux="";
int tam=cad.length();
for(int i=0; i<tam; i++)
{if((cad.charAt(i)>=65 &&cad.charAt(i)<=90)||(cad.charAt(i)>=97 &&cad.charAt(i)<=122))
aux+=' ';
else
aux+=cad.charAt(i);
}
return aux;
}
public String pegarcad(String cad2)
{
int tam=cad2.length();
for(int i=0; i<tam; i++)
{
cad+= cad2.charAt(i);
}
return cad;
}
}
PARTE DE PRESENTACION:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Formulario.java
*
* Created on 7/03/2011, 07:30:02 PM
*/
package Ilustrar;
import Logica.Proceso;
import javax.swing.JOptionPane;
/**
*
* @author Administrador
*/
public class Formulario extends java.applet.Applet {
/** Initializes the applet Formulario */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
TEXTO1 = new javax.swing.JLabel();
ESCRITO1 = new javax.swing.JTextField();
ESCRITO2 = new javax.swing.JTextField();
BOTON1 = new javax.swing.JButton();
BOTON2 = new javax.swing.JButton();
BONTON3 = new javax.swing.JButton();
ESCRITO3 = new javax.swing.JTextField();
TEXTO2 = new javax.swing.JLabel();
boton4 = new javax.swing.JButton();
BONTON5 = new javax.swing.JButton();
BONTON6 = new javax.swing.JButton();
BOTON7 = new javax.swing.JButton();
BOTON8 = new javax.swing.JButton();
setBackground(new java.awt.Color(255, 255, 153));
jLabel1.setText("Programa para el manejo de caracteres");
TEXTO1.setText("Digite dos cadenas");
ESCRITO1.setBackground(new java.awt.Color(0, 255, 255));
ESCRITO2.setBackground(new java.awt.Color(0, 255, 255));
ESCRITO2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ESCRITO2ActionPerformed(evt);
}
});
BOTON1.setText("imprimir cadena1");
BOTON1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BOTON1ActionPerformed(evt);
}
});
BOTON2.setText("imprimir cadena 2");
BOTON2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BOTON2ActionPerformed(evt);
}
});
BONTON3.setText("mostrar cadenas unidas");
BONTON3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BONTON3ActionPerformed(evt);
}
});
ESCRITO3.setBackground(new java.awt.Color(102, 255, 255));
TEXTO2.setBackground(new java.awt.Color(0, 255, 255));
TEXTO2.setText("digite texto");
boton4.setBackground(new java.awt.Color(255, 255, 255));
boton4.setText("Hallar cantidad de palabras");
boton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
boton4ActionPerformed(evt);
}
});
BONTON5.setText("monstrar frase sin espacios");
BONTON5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BONTON5ActionPerformed(evt);
}
});
BONTON6.setText("mostrar sin vocales");
BONTON6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BONTON6ActionPerformed(evt);
}
});
BOTON7.setText("Mostrar sin letras");
BOTON7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BOTON7ActionPerformed(evt);
}
});
BOTON8.setText("Mostrar sin letras ni vocales");
BOTON8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BOTON8ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.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(206, 206, 206)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(67, 67, 67)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(TEXTO1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 168, Short.MAX_VALUE))
.addComponent(ESCRITO1, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
.addComponent(ESCRITO2, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE))
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(BOTON2, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(BOTON1, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(47, 47, 47)
.addComponent(BONTON3)
.addGap(630, 630, 630))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(55, 55, 55)
.addComponent(TEXTO2, javax.swing.GroupLayout.DEFAULT_SIZE, 967, Short.MAX_VALUE)
.addGap(205, 205, 205))
.addGroup(layout.createSequentialGroup()
.addGap(72, 72, 72)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(BONTON6)
.addGap(35, 35, 35)
.addComponent(BOTON7))
.addGroup(layout.createSequentialGroup()
.addComponent(ESCRITO3, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(BONTON5)
.addComponent(boton4))))))
.addGap(73, 73, 73))
.addGroup(layout.createSequentialGroup()
.addGap(161, 161, 161)
.addComponent(BOTON8)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel1)
.addGap(38, 38, 38)
.addComponent(TEXTO1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ESCRITO1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BOTON1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ESCRITO2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BOTON2))
.addGap(35, 35, 35))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BONTON3)
.addGap(62, 62, 62)))
.addComponent(TEXTO2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(boton4)
.addGap(18, 18, 18)
.addComponent(BONTON5))
.addComponent(ESCRITO3, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(BONTON6)
.addComponent(BOTON7))
.addGap(18, 18, 18)
.addComponent(BOTON8)
.addContainerGap(111, Short.MAX_VALUE))
);
}// </editor-fold>
private void ESCRITO2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void BOTON1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Proceso obj1=new Proceso();
obj1.setCad(ESCRITO1.getText());
JOptionPane.showMessageDialog(null, obj1.getCad());
}
private void BOTON2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Proceso obj2=new Proceso();
obj2.setCad(ESCRITO2.getText());
JOptionPane.showMessageDialog(null, obj2.getCad());
}
private void BONTON3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Proceso obj1=new Proceso();
Proceso obj2=new Proceso();
obj1.setCad(ESCRITO1.getText());
obj2.setCad(ESCRITO2.getText());
JOptionPane.showMessageDialog(null, obj1.pegarcad(obj2.getCad()));
}
private void boton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Proceso obj1=new Proceso();
obj1.setCad(ESCRITO3.getText());
JOptionPane.showMessageDialog(null,"LA FRASE: "+obj1.getCad()+"\n tiene "+ obj1.hallarPalabras()+" palabras");
}
private void BONTON5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Proceso obj1=new Proceso ();
obj1.setCad(ESCRITO3.getText());
JOptionPane.showMessageDialog(null,obj1.imprimirSE());
}
private void BONTON6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Proceso obj1=new Proceso();
obj1.setCad(ESCRITO3.getText());
JOptionPane.showMessageDialog(null,obj1.imprimirSV());
}
private void BOTON7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Proceso obj= new Proceso ();
obj.setCad(ESCRITO3.getText());
JOptionPane.showMessageDialog(null,obj.imprimirSL());
}
private void BOTON8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Proceso obj= new Proceso ();
obj.setCad(ESCRITO3.getText());
JOptionPane.showMessageDialog(null,obj.imprimirSLV());
}
// Variables declaration - do not modify
private javax.swing.JButton BONTON3;
private javax.swing.JButton BONTON5;
private javax.swing.JButton BONTON6;
private javax.swing.JButton BOTON1;
private javax.swing.JButton BOTON2;
private javax.swing.JButton BOTON7;
private javax.swing.JButton BOTON8;
private javax.swing.JTextField ESCRITO1;
private javax.swing.JTextField ESCRITO2;
private javax.swing.JTextField ESCRITO3;
private javax.swing.JLabel TEXTO1;
private javax.swing.JLabel TEXTO2;
private javax.swing.JButton boton4;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}