Guest User

Untitled

a guest
May 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public void actionPerformed2(ActionEvent f) {
  2. String palabra = interfaz.getTexto1();
  3.  
  4. String conversion2 = convertidor.convertirTextoMorse(palabra);
  5. interfaz.settextoMorse(conversion2);
  6.  
  7. }
  8.  
  9. private void actionListener2(ActionListener f) {
  10. interfaz.btnTexto.addActionListener(f);
  11.  
  12. }
  13.  
  14. public class Convertidor {
  15.  
  16. public String convertirTextoMorse(String palabra) {
  17.  
  18. String morse[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", // a-i
  19. ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", // j-q
  20. ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".......", // r-" "
  21. ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", // A-G
  22. "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", // H-P
  23. "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", // Q-X
  24. "-.--", "--..", "......." }; // Y-Z
  25.  
  26. String abecedario = (String) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
  27. int posicion = 0;
  28. String conversion = "";
  29.  
  30. for (int f = 0; f < palabra.length(); f++) {
  31. posicion = abecedario.indexOf(palabra.charAt(f));
  32. conversion = conversion + morse[posicion] + " ";
  33.  
  34. }
  35. return conversion;
  36.  
  37. }
Add Comment
Please, Sign In to add comment