Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 24, 2022 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/c5e4e6271084f2539220be259843d160 to your computer and use it in GitHub Desktop.
Save parzibyte/c5e4e6271084f2539220be259843d160 to your computer and use it in GitHub Desktop.
private void jButtonTraducirActionPerformed(java.awt.event.ActionEvent evt) {
String entrada = this.jTextFieldEntrada.getText();
if (entrada.length() <= 0) {
JOptionPane.showMessageDialog(null, "No has ingresado nada para traducir");
return;
}
HashMap<String, String> traducciones = new HashMap<>();
// Lo único que aprendí en mi clase de inglés:
traducciones.put("hola", "hello");
traducciones.put("perro", "dog");
traducciones.put("gato", "cat");
traducciones.put("¿Puedo ir al baño?", "May I go to the bathroom?");
// Aquí más traducciones...
String traduccion = traducciones.get(entrada);
if (traduccion == null) {
this.jLabelResultado.setText("No encontrado");
} else {
this.jLabelResultado.setText(traduccion);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment