Guest User

Untitled

a guest
Feb 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  2. String texto = txt.getText();
  3. String impresion = "Palabras clave: ";
  4. String anadir = "";
  5. String anadir1 = "";
  6. ArrayList<String> palabras = new ArrayList();
  7. ArrayList<String> palabrasclave = new ArrayList();
  8. int n = 0;
  9. int longitudtexto = texto.length() - 1;
  10.  
  11. if (texto.charAt(longitudtexto) != '.' || texto.charAt(longitudtexto) != ' ' || texto.charAt(longitudtexto) != ',') {
  12. texto += ".";
  13. }
  14.  
  15. for (int x = 0; x < texto.length(); x++) {
  16. if (texto.charAt(x) == ' ' || texto.charAt(x) == '.' || texto.charAt(x) == ',') {
  17. palabras.add(anadir);
  18. anadir = "";
  19. } else {
  20. anadir += texto.charAt(x);
  21. }
  22.  
  23. }
  24.  
  25. for (int i = 0; i < palabras.size(); i++) {
  26.  
  27. String palabraencuestion = palabras.get(i);
  28.  
  29. for (int y = 0; y < palabras.size(); y++) {
  30.  
  31. if (palabrasclave.contains(palabraencuestion)) {
  32. contiene = true;
  33. } else {
  34. contiene = false;
  35. }
  36. String palabra = palabras.get(y);
  37.  
  38. if (palabraencuestion.equals(palabra) && i != y && contiene == false) {
  39.  
  40. palabrasclave.add(palabraencuestion);
  41.  
  42. }
  43. }
  44. }
  45.  
  46. for (int y = 0; y < palabrasclave.size(); y++) {
  47.  
  48. anadir1 += palabrasclave.get(y);
  49. if (y != 0 || y != palabrasclave.size()) {
  50. anadir1 += " - ";
  51. }
  52. }
  53.  
  54. lbl.setText("Las palabras clave son: " + anadir1);
  55. }
Add Comment
Please, Sign In to add comment