¿QUE LES PARECIO SE PUEDE MEJORAR?

jueves, 6 de octubre de 2011

EJEMPLO- COLECCIONES

miren este programita de colecciones!!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* CONJUNTOS.java
*
* Created on 26/09/2011, 01:35:54 PM
*/
package Problema4_CONJUNTOS;
 
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import javax.swing.JTextArea;
/**
*
* @author alumno
*/
public class ClasificacionDeCaracteres extends javax.swing.JFrame {
/** Creates new form CONJUNTOS */
public ClasificacionDeCaracteres() {
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>//GEN-END:initComponents
Set Mayus=new TreeSet();
Set Minus=new TreeSet();
Set Simbolos=new TreeSet();
Set Digitos= new TreeSet();
Set TODOS= new TreeSet();
public void MuestraColeccion(Collection con,JTextArea txtSalida)
{
Iterator iter=con.iterator();
String msj="";
while(iter.hasNext())
{
msj+=iter.next()+"";
}
txtSalida.append(msj+"\n");
}
private void btnIngresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIngresarActionPerformed
// TODO add your handling code here:
String s=txtIngreso1.getText();
char ch=s.charAt(0);
if(Character.isUpperCase(ch)) Mayus.add(ch);
else if(Character.isLowerCase(ch)) Minus.add(ch);
else if(Character.isDigit(ch)) Digitos.add(ch);
else Simbolos.add(ch);
this.txtIngreso1.setText("");
this.txtIngreso1.requestFocus();
 
}//GEN-LAST:event_btnIngresarActionPerformed
private void btnMOSTRARActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMOSTRARActionPerformed
// TODO add your handling code here:
txtSalida.setText("");
txtSalida.append(" Mayusculas:\t");
this.MuestraColeccion(Mayus, txtSalida);
txtSalida.append("\n Minusculas:\t");
this.MuestraColeccion(Minus, txtSalida);
txtSalida.append("\n Digitos:\t");
this.MuestraColeccion(Digitos, txtSalida);
txtSalida.append("\n Simbolos:\t");
this.MuestraColeccion(Simbolos, txtSalida);
}//GEN-LAST:event_btnMOSTRARActionPerformed

private void btnUNIRcoleccionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUNIRcoleccionesActionPerformed
// TODO add your handling code here:
txtSalida.setText("");
TODOS.addAll(Mayus);
TODOS.addAll(Minus);
TODOS.addAll(Digitos);
TODOS.addAll(Simbolos);
txtSalida.append("\nTODOS UNIDOS:\t");
this.MuestraColeccion(TODOS, txtSalida);
}//GEN-LAST:event_btnUNIRcoleccionesActionPerformed
public void Eliminar()
{
Mayus.removeAll(Mayus);
Minus.removeAll(Minus);
Digitos.removeAll(Digitos);
Simbolos.removeAll(Simbolos);
TODOS.removeAll(TODOS);
}
private void btnEliminarConjuntosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarConjuntosActionPerformed
// TODO add your handling code here:
txtSalida.setText("");
this.Eliminar();
txtSalida.append("ELIMINADOS");
}//GEN-LAST:event_btnEliminarConjuntosActionPerformed
private void btnLIMPIARActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLIMPIARActionPerformed
// TODO add your handling code here:
txtSalida.setText("");
txtIngreso1.requestFocus();
}//GEN-LAST:event_btnLIMPIARActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ClasificacionDeCaracteres().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnEliminarConjuntos;
private javax.swing.JButton btnIngresar;
private javax.swing.JButton btnLIMPIAR;
private javax.swing.JButton btnMOSTRAR;
private javax.swing.JButton btnUNIRcolecciones;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField txtIngreso1;
private javax.swing.JTextArea txtSalida;
// End of variables declaration//GEN-END:variables
}

No hay comentarios:

Publicar un comentario